r181390 - In block enum-return inference, don't die on loads of enum lvalues.

John McCall rjmccall at apple.com
Tue May 7 20:34:23 PDT 2013


Author: rjmccall
Date: Tue May  7 22:34:22 2013
New Revision: 181390

URL: http://llvm.org/viewvc/llvm-project?rev=181390&view=rev
Log:
In block enum-return inference, don't die on loads of enum lvalues.

More of rdar://13200889.

Modified:
    cfe/trunk/lib/Sema/SemaLambda.cpp
    cfe/trunk/test/SemaObjC/blocks.m

Modified: cfe/trunk/lib/Sema/SemaLambda.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLambda.cpp?rev=181390&r1=181389&r2=181390&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLambda.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLambda.cpp Tue May  7 22:34:22 2013
@@ -275,11 +275,12 @@ static EnumDecl *findEnumForBlockReturn(
   //   - it is an implicit integral conversion applied to an
   //     enumerator-like expression of type T or
   if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(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.

Modified: cfe/trunk/test/SemaObjC/blocks.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/blocks.m?rev=181390&r1=181389&r2=181390&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/blocks.m (original)
+++ cfe/trunk/test/SemaObjC/blocks.m Tue May  7 22:34:22 2013
@@ -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 = ^{





More information about the cfe-commits mailing list