[cfe-commits] r73041 - in /cfe/trunk: lib/AST/ASTContext.cpp lib/Frontend/RewriteBlocks.cpp lib/Sema/SemaExpr.cpp test/Sema/block-args.c test/Sema/block-call.c test/Sema/block-misc.c test/SemaObjC/blocks.m

Eli Friedman eli.friedman at gmail.com
Sun Jun 7 21:24:21 PDT 2009


Author: efriedma
Date: Sun Jun  7 23:24:21 2009
New Revision: 73041

URL: http://llvm.org/viewvc/llvm-project?rev=73041&view=rev
Log:
Don't allow defining a block with a non-prototype type.  Remove a 
hack which introduces some strange inconsistencies in compatibility 
for block pointers.

Note that unlike an earlier revision proposed on cfe-commits, this patch 
still allows declaring block pointers without a prototype.


Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Frontend/RewriteBlocks.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/block-args.c
    cfe/trunk/test/Sema/block-call.c
    cfe/trunk/test/Sema/block-misc.c
    cfe/trunk/test/SemaObjC/blocks.m

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=73041&r1=73040&r2=73041&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun Jun  7 23:24:21 2009
@@ -2853,12 +2853,6 @@
 /// FIXME: When the dust settles on this integration, fold this into mergeTypes.
 ///
 bool ASTContext::typesAreBlockCompatible(QualType lhs, QualType rhs) {
-  const FunctionType *lbase = lhs->getAsFunctionType();
-  const FunctionType *rbase = rhs->getAsFunctionType();
-  const FunctionProtoType *lproto = dyn_cast<FunctionProtoType>(lbase);
-  const FunctionProtoType *rproto = dyn_cast<FunctionProtoType>(rbase);
-  if (lproto && rproto == 0)
-    return false;
   return !mergeTypes(lhs, rhs).isNull();
 }
 

Modified: cfe/trunk/lib/Frontend/RewriteBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteBlocks.cpp?rev=73041&r1=73040&r2=73041&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/RewriteBlocks.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteBlocks.cpp Sun Jun  7 23:24:21 2009
@@ -1011,9 +1011,7 @@
        CI != E; ++CI)
     if (*CI) {
       if (BlockExpr *CBE = dyn_cast<BlockExpr>(*CI)) {
-        Stmt *newStmt = RewriteFunctionBody(CBE->getBody());
-        if (newStmt) 
-          *CI = newStmt;
+        RewriteFunctionBody(CBE->getBody());
           
         // We've just rewritten the block body in place.
         // Now we snarf the rewritten text and stash it away for later use.
@@ -1023,9 +1021,7 @@
         // Do the rewrite, using S.size() which contains the rewritten size.
         ReplaceText(CBE->getLocStart(), S.size(), Init.c_str(), Init.size());
       } else {
-        Stmt *newStmt = RewriteFunctionBody(*CI);
-        if (newStmt) 
-          *CI = newStmt;
+        RewriteFunctionBody(*CI);
       }
     }
   // Handle specific things.

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=73041&r1=73040&r2=73041&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Jun  7 23:24:21 2009
@@ -5220,7 +5220,7 @@
 
   QualType BlockTy;
   if (!BSI->hasPrototype)
-    BlockTy = Context.getFunctionNoProtoType(RetTy);
+    BlockTy = Context.getFunctionType(RetTy, 0, 0, false, 0);
   else
     BlockTy = Context.getFunctionType(RetTy, ArgTypes.data(), ArgTypes.size(),
                                       BSI->isVariadic, 0);

Modified: cfe/trunk/test/Sema/block-args.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-args.c?rev=73041&r1=73040&r2=73041&view=diff

==============================================================================
--- cfe/trunk/test/Sema/block-args.c (original)
+++ cfe/trunk/test/Sema/block-args.c Sun Jun  7 23:24:21 2009
@@ -18,7 +18,7 @@
   ^{return 1;}();
   ^{return 2;}(arg); // expected-error {{too many arguments to block call}}
   ^(void){return 3;}(1); // expected-error {{too many arguments to block call}}
-  ^(){return 4;}(arg);   // C style (...), ok.
+  ^(){return 4;}(arg); // expected-error {{too many arguments to block call}}
   ^(int x, ...){return 5;}(arg, arg);   // Explicit varargs, ok.
 }
 

Modified: cfe/trunk/test/Sema/block-call.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-call.c?rev=73041&r1=73040&r2=73041&view=diff

==============================================================================
--- cfe/trunk/test/Sema/block-call.c (original)
+++ cfe/trunk/test/Sema/block-call.c Sun Jun  7 23:24:21 2009
@@ -7,10 +7,10 @@
   int (*FPL) (int) = FP; // C doesn't consider this an error.
   
   // For Blocks, the ASTContext::typesAreBlockCompatible() makes sure this is an error.
-  int (^PFR) (int) = IFP;	// expected-error {{incompatible block pointer types initializing 'int (^)()', expected 'int (^)(int)'}}
+  int (^PFR) (int) = IFP; // OK
 	PFR = II;	// OK
 
-	int (^IFP) () = PFR;
+	int (^IFP) () = PFR; // OK
 
 
 	const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int (^)()', expected 'int const (^)()'}}

Modified: cfe/trunk/test/Sema/block-misc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-misc.c?rev=73041&r1=73040&r2=73041&view=diff

==============================================================================
--- cfe/trunk/test/Sema/block-misc.c (original)
+++ cfe/trunk/test/Sema/block-misc.c Sun Jun  7 23:24:21 2009
@@ -10,7 +10,7 @@
   if (PFR == II)	// OK
     donotwarn();
 
-  if (PFR == IFP) // expected-error {{comparison of distinct block types}}
+  if (PFR == IFP) // OK
     donotwarn();
 
   if (PFR == (int (^) (int))IFP) // OK
@@ -25,7 +25,7 @@
   if (!PFR)	// OK
     donotwarn();
 
-  return PFR != IFP;	// expected-error {{comparison of distinct block types}}
+  return PFR != IFP;	// OK
 }
 
 int test2(double (^S)()) {
@@ -165,7 +165,7 @@
 
   f(1 ? bp : vp);
   f(1 ? vp : bp);
-  f(1 ? bp : bp1); // expected-error {{incompatible operand types ('void (^)(int)' and 'void (^)()')}}
+  f(1 ? bp : bp1);
   (void)(bp > rp); // expected-error {{invalid operands}}
   (void)(bp > 0); // expected-error {{invalid operands}}
   (void)(bp > bp); // expected-error {{invalid operands}}

Modified: cfe/trunk/test/SemaObjC/blocks.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/blocks.m?rev=73041&r1=73040&r2=73041&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/blocks.m (original)
+++ cfe/trunk/test/SemaObjC/blocks.m Sun Jun  7 23:24:21 2009
@@ -28,7 +28,7 @@
 
 void bar6(id(^)(int));
 void foo6(id (^objectCreationBlock)()) {
-    return bar6(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)()', expected 'id (^)(int)'}}
+    return bar6(objectCreationBlock);
 }
 
 void foo7(id (^x)(int)) {





More information about the cfe-commits mailing list