[cfe-commits] r65751 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp test/CodeGenObjC/blocks-unsupported.m
Anders Carlsson
andersca at mac.com
Sat Feb 28 17:45:25 PST 2009
Author: andersca
Date: Sat Feb 28 19:45:25 2009
New Revision: 65751
URL: http://llvm.org/viewvc/llvm-project?rev=65751&view=rev
Log:
Emit errors about unsupported blocks features.
Added:
cfe/trunk/test/CodeGenObjC/blocks-unsupported.m
Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=65751&r1=65750&r2=65751&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Sat Feb 28 19:45:25 2009
@@ -132,6 +132,44 @@
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];
+
+ E->getType()->dump();
+
+ 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) {
@@ -144,6 +182,9 @@
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;
Added: cfe/trunk/test/CodeGenObjC/blocks-unsupported.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/blocks-unsupported.m?rev=65751&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/blocks-unsupported.m (added)
+++ cfe/trunk/test/CodeGenObjC/blocks-unsupported.m Sat Feb 28 19:45:25 2009
@@ -0,0 +1,34 @@
+// RUN: clang -fnext-runtime --emit-llvm -o %t %s -verify
+
+ at class Foo;
+ at protocol P;
+
+void t1()
+{
+ __block int a;
+ ^{ a = 10; }(); // expected-error {{cannot compile this block expression with __block variables 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}}
+
+ typedef struct CGColor * __attribute__ ((NSObject)) CGColorRef;
+ CGColorRef color;
+ ^{ (void)color; }(); // expected-error {{cannot compile this block expression with __attribute__((NSObject)) variable yet}}
+
+ id a1;
+ ^{ (void)a1; }(); // expected-error {{cannot compile this block expression with Objective-C variable yet}}
+
+ Foo *a2;
+ ^{ (void)a2; }(); // expected-error {{cannot compile this block expression with Objective-C variable yet}}
+
+ id<P> a3;
+ ^{ (void)a3; }(); // expected-error {{cannot compile this block expression with Objective-C variable yet}}
+
+ Foo<P> *a4;
+ ^{ (void)a4; }(); // expected-error {{cannot compile this block expression with Objective-C variable yet}}
+
+
+}
More information about the cfe-commits
mailing list