[cfe-commits] r65798 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp lib/CodeGen/CGExpr.cpp test/CodeGenObjC/blocks-unsupported.m

Mike Stump mrs at apple.com
Sun Mar 1 19:04:43 PST 2009


Author: mrs
Date: Sun Mar  1 21:04:42 2009
New Revision: 65798

URL: http://llvm.org/viewvc/llvm-project?rev=65798&view=rev
Log:
Push checking down, also, give the user a hit as to which part of the
block literal is causing the problem, instead of the vague reference
to the entire block literal.

Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/CodeGenObjC/blocks-unsupported.m

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=65798&r1=65797&r2=65798&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Sun Mar  1 21:04:42 2009
@@ -132,42 +132,6 @@
   return Info.ByRefDeclRefs.empty() && Info.ByCopyDeclRefs.empty();
 }
 
-/// CanGenerateCodeForBlockExpr - Returns whether CodeGen for the block expr
-/// is supported. Will emit a diagnostic and return false if not.
-/// FIXME: Once we support everything this should of course be removed.
-static bool CanGenerateCodeForBlockExpr(CodeGenFunction &CGF, 
-                                        const BlockExpr* BE, 
-                                        const CodeGenFunction::BlockInfo &Info)
-{
-  if (!Info.ByRefDeclRefs.empty()) {
-    CGF.ErrorUnsupported(BE, "block expression with __block variables");
-    return false;
-  }
-  
-  for (size_t I = 0, E = Info.ByCopyDeclRefs.size(); I != E; ++I) {
-    const BlockDeclRefExpr *E = Info.ByCopyDeclRefs[I];
-    
-    if (E->getType()->isBlockPointerType()) {
-      CGF.ErrorUnsupported(BE, "block expression with imported block");
-      return false;
-    }
-    
-    if (E->getDecl()->getAttr<ObjCNSObjectAttr>() || 
-        CGF.getContext().isObjCNSObjectType(E->getType())) {
-      CGF.ErrorUnsupported(BE, "block expression with __attribute__((NSObject))"
-                           " variable");
-      return false;
-    }
-    
-    if (CGF.getContext().isObjCObjectPointerType(E->getType())) {
-      CGF.ErrorUnsupported(BE, "block expression with Objective-C variable");
-      return false;
-    }
-  }
-  
-  return true;
-}
-
 // FIXME: Push most into CGM, passing down a few bits, like current
 // function name.
 llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) {
@@ -180,9 +144,6 @@
   if (CanBlockBeGlobal(Info))
     return CGM.GetAddrOfGlobalBlock(BE, Name.c_str());
     
-  if (!CanGenerateCodeForBlockExpr(*this, BE, Info))
-    return llvm::UndefValue::get(ConvertType(BE->getType()));
-  
   std::vector<llvm::Constant*> Elts;
   llvm::Constant *C;
   llvm::Value *V;

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=65798&r1=65797&r2=65798&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sun Mar  1 21:04:42 2009
@@ -674,6 +674,17 @@
   const llvm::Type *Ty;
   Ty = CGM.getTypes().ConvertType(E->getDecl()->getType());
 
+  if (E->isByRef())
+    ErrorUnsupported(E, "__block variable in block literal");
+  else if (E->getType()->isBlockPointerType())
+    ErrorUnsupported(E, "block pointer in block literal");
+  else if (E->getDecl()->getAttr<ObjCNSObjectAttr>() || 
+           getContext().isObjCNSObjectType(E->getType()))
+    ErrorUnsupported(E, "__attribute__((NSObject)) variable in block "
+                     "literal");
+  else if (getContext().isObjCObjectPointerType(E->getType()))
+    ErrorUnsupported(E, "Objective-C variable in block literal");
+
   // See if we have already allocated an offset for this variable.
   if (offset == 0) {
     // if not, allocate one now.

Modified: cfe/trunk/test/CodeGenObjC/blocks-unsupported.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/blocks-unsupported.m?rev=65798&r1=65797&r2=65798&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenObjC/blocks-unsupported.m (original)
+++ cfe/trunk/test/CodeGenObjC/blocks-unsupported.m Sun Mar  1 21:04:42 2009
@@ -6,29 +6,29 @@
 void t1()
 {
 	__block int a;
-	^{ a = 10; }(); // expected-error {{cannot compile this block expression with __block variables yet}}
+	^{ a = 10; }(); // expected-error {{cannot compile this __block variable in block literal yet}}
 	
 	void (^block)(void);
     ^{ (void)block; }(); // expected-error {{}}
 
     struct Foo *__attribute__ ((NSObject)) foo;
-    ^{ (void)foo; }(); // expected-error {{cannot compile this block expression with __attribute__((NSObject)) variable yet}}
+    ^{ (void)foo; }(); // expected-error {{cannot compile this __attribute__((NSObject)) variable in block literal yet}}
     
     typedef struct CGColor * __attribute__ ((NSObject)) CGColorRef;
     CGColorRef color;
-    ^{ (void)color; }(); // expected-error {{cannot compile this block expression with __attribute__((NSObject)) variable yet}}
+    ^{ (void)color; }(); // expected-error {{cannot compile this __attribute__((NSObject)) variable in block literal yet}}
     
     id a1;
-    ^{ (void)a1; }(); // expected-error {{cannot compile this block expression with Objective-C variable yet}}
+    ^{ (void)a1; }(); // expected-error {{cannot compile this Objective-C variable in block literal yet}}
     
     Foo *a2;
-    ^{ (void)a2; }(); // expected-error {{cannot compile this block expression with Objective-C variable yet}}
+    ^{ (void)a2; }(); // expected-error {{cannot compile this Objective-C variable in block literal yet}}
     
     id<P> a3;
-    ^{ (void)a3; }(); // expected-error {{cannot compile this block expression with Objective-C variable yet}}
+    ^{ (void)a3; }(); // expected-error {{cannot compile this Objective-C variable in block literal yet}}
 
     Foo<P> *a4;
-    ^{ (void)a4; }(); // expected-error {{cannot compile this block expression with Objective-C variable yet}}
+    ^{ (void)a4; }(); // expected-error {{cannot compile this Objective-C variable in block literal yet}}
     
     
 }





More information about the cfe-commits mailing list