[cfe-commits] r145782 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/Sema/block-return.c test/SemaCXX/instantiate-blocks.cpp

Fariborz Jahanian fjahanian at apple.com
Sat Dec 3 15:53:56 PST 2011


Author: fjahanian
Date: Sat Dec  3 17:53:56 2011
New Revision: 145782

URL: http://llvm.org/viewvc/llvm-project?rev=145782&view=rev
Log:
Move block return type inference diagnostic to a common place where
Function or array lvalue conversions happens.


Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/Sema/block-return.c
    cfe/trunk/test/SemaCXX/instantiate-blocks.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=145782&r1=145781&r2=145782&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sat Dec  3 17:53:56 2011
@@ -1760,7 +1760,8 @@
   // If this is the first return we've seen in the block, infer the type of
   // the block from it.
   BlockScopeInfo *CurBlock = getCurBlock();
-  if (CurBlock->ReturnType.isNull()) {
+  if (CurBlock->TheDecl->blockMissingReturnType()) {
+    QualType BlockReturnT;
     if (RetValExp) {
       // Don't call UsualUnaryConversions(), since we don't want to do
       // integer promotions here.
@@ -1770,7 +1771,7 @@
       RetValExp = Result.take();
 
       if (!RetValExp->isTypeDependent()) {
-        CurBlock->ReturnType = RetValExp->getType();
+        BlockReturnT = RetValExp->getType();
         if (BlockDeclRefExpr *CDRE = dyn_cast<BlockDeclRefExpr>(RetValExp)) {
           // We have to remove a 'const' added to copied-in variable which was
           // part of the implementation spec. and not the actual qualifier for
@@ -1779,9 +1780,19 @@
             CurBlock->ReturnType.removeLocalConst(); // FIXME: local???
         }
       } else
-        CurBlock->ReturnType = Context.DependentTy;
+        BlockReturnT = Context.DependentTy;
     } else
-      CurBlock->ReturnType = Context.VoidTy;
+        BlockReturnT = Context.VoidTy;
+    if (!CurBlock->ReturnType.isNull() && !CurBlock->ReturnType->isDependentType()
+        && !BlockReturnT->isDependentType() 
+        // when block's return type is not specified, all return types
+        // must strictly match.
+        && !Context.hasSameType(BlockReturnT, CurBlock->ReturnType)) { 
+        Diag(ReturnLoc, diag::err_typecheck_missing_return_type_incompatible) 
+            << BlockReturnT << CurBlock->ReturnType;
+        return StmtError();
+    }
+    CurBlock->ReturnType = BlockReturnT;
   }
   QualType FnRetType = CurBlock->ReturnType;
 
@@ -1809,16 +1820,6 @@
   } else if (!RetValExp) {
     return StmtError(Diag(ReturnLoc, diag::err_block_return_missing_expr));
   } else if (!RetValExp->isTypeDependent()) {
-    if (CurBlock->TheDecl->blockMissingReturnType()) {
-      // when block's return type is not specified, all return types
-      // must strictly match.
-      if (Context.getCanonicalType(FnRetType) != 
-          Context.getCanonicalType(RetValExp->getType())) {
-          Diag(ReturnLoc, diag::err_typecheck_missing_return_type_incompatible) 
-            << RetValExp->getType() << FnRetType;
-          return StmtError();
-      }
-    }
     // we have a non-void block with an expression, continue checking
 
     // C99 6.8.6.4p3(136): The return statement is not an assignment. The

Modified: cfe/trunk/test/Sema/block-return.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-return.c?rev=145782&r1=145781&r2=145782&view=diff
==============================================================================
--- cfe/trunk/test/Sema/block-return.c (original)
+++ cfe/trunk/test/Sema/block-return.c Sat Dec  3 17:53:56 2011
@@ -9,14 +9,14 @@
   CL X = ^{
     if (2)
       return;
-    return 1;  // expected-error {{void block should not return a value}}
+    return 1;  // expected-error {{return type 'int' must match previous return type 'void' when block literal has unspecified explicit return type}}
   };
 
   int (^Y) (void)  = ^{
     if (3)
       return 1;
     else
-      return; // expected-error {{non-void block should return a value}}
+      return; // expected-error {{return type 'void' must match previous return type 'int' when block literal has unspecified explicit return type}}
   };
 
   char *(^Z)(void) = ^{

Modified: cfe/trunk/test/SemaCXX/instantiate-blocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/instantiate-blocks.cpp?rev=145782&r1=145781&r2=145782&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/instantiate-blocks.cpp (original)
+++ cfe/trunk/test/SemaCXX/instantiate-blocks.cpp Sat Dec  3 17:53:56 2011
@@ -19,7 +19,7 @@
     if (1)
       return t;
     else if (2)
-      return r;  // expected-error {{return type 'const double' must match previous return type 'float' when block literal has unspecified explicit return type}}
+      return r;  // expected-error {{return type 'double' must match previous return type 'float' when block literal has unspecified explicit return type}}
   };
 }
 





More information about the cfe-commits mailing list