From 70133b5b4ad863f7d73fabfaf799b2f4e30d98ec Mon Sep 17 00:00:00 2001 From: John McCall Date: Wed, 8 May 2013 03:34:22 +0000 Subject: [PATCH] In block enum-return inference, don't die on loads of enum lvalues. More of rdar://13200889. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181390 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaLambda.cpp | 7 ++++--- test/SemaObjC/blocks.m | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp index c7ba3cc822..24388dd0f5 100644 --- a/lib/Sema/SemaLambda.cpp +++ b/lib/Sema/SemaLambda.cpp @@ -275,11 +275,12 @@ static EnumDecl *findEnumForBlockReturn(Expr *E) { // - it is an implicit integral conversion applied to an // enumerator-like expression of type T or if (ImplicitCastExpr *ICE = dyn_cast(E)) { - // We can only see integral conversions in valid enumerator-like - // expressions. + // We can sometimes see integral conversions in valid + // enumerator-like expressions. if (ICE->getCastKind() == CK_IntegralCast) return findEnumForBlockReturn(ICE->getSubExpr()); - return 0; + + // Otherwise, just rely on the type. } // - it is an expression of that formal enum type. diff --git a/test/SemaObjC/blocks.m b/test/SemaObjC/blocks.m index b523e4c916..65434698a8 100644 --- a/test/SemaObjC/blocks.m +++ b/test/SemaObjC/blocks.m @@ -86,9 +86,11 @@ typedef enum CStyleEnum (^cse_block_t)(); void testCStyleEnumInference(bool arg) { cse_block_t a; + enum CStyleEnum value; // No warnings here. a = ^{ return getCSE(); }; + a = ^{ return value; }; a = ^{ // expected-error {{incompatible block pointer types assigning to 'cse_block_t' (aka 'enum CStyleEnum (^)()') from 'int (^)(void)'}} return 1; @@ -102,6 +104,7 @@ void testCStyleEnumInference(bool arg) { // No warnings here. a = ^{ if (arg) return CSE_Value; else return getCSE(); }; a = ^{ if (arg) return getCSE(); else return CSE_Value; }; + a = ^{ if (arg) return value; else return CSE_Value; }; // These two blocks actually return 'int' a = ^{ // expected-error {{incompatible block pointer types assigning to 'cse_block_t' (aka 'enum CStyleEnum (^)()') from 'int (^)(void)'}} @@ -118,6 +121,13 @@ void testCStyleEnumInference(bool arg) { return 1; }; + a = ^{ // expected-error {{incompatible block pointer types assigning to 'cse_block_t' (aka 'enum CStyleEnum (^)()') from 'int (^)(void)'}} + if (arg) + return 1; + else + return value; // expected-error {{return type 'enum CStyleEnum' must match previous return type 'int'}} + }; + // rdar://13200889 extern void check_enum(void); a = ^{ -- 2.40.0