[cfe-commits] r56955 - in /cfe/trunk: Driver/RewriteBlocks.cpp lib/Sema/SemaDecl.cpp test/Sema/block-literal.c
Steve Naroff
snaroff at apple.com
Thu Oct 2 10:12:57 PDT 2008
Author: snaroff
Date: Thu Oct 2 12:12:56 2008
New Revision: 56955
URL: http://llvm.org/viewvc/llvm-project?rev=56955&view=rev
Log:
Changed Sema::CheckForConstantInitializer to allow global block literals.
This commit also includes some name changes in the blocks rewriter (no functionality change).
Modified:
cfe/trunk/Driver/RewriteBlocks.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/block-literal.c
Modified: cfe/trunk/Driver/RewriteBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteBlocks.cpp?rev=56955&r1=56954&r2=56955&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteBlocks.cpp (original)
+++ cfe/trunk/Driver/RewriteBlocks.cpp Thu Oct 2 12:12:56 2008
@@ -186,18 +186,18 @@
Rewrite.setSourceMgr(Context->getSourceManager());
const char *s = "#pragma once\n"
- "#ifndef CLOSURE_IMPL\n"
- "struct __closure_impl {\n"
- " long Reserved;\n"
+ "#ifndef BLOCK_IMPL\n"
+ "struct __block_impl {\n"
+ " void *isa;\n"
" int Flags;\n"
" int Size;\n"
- " void *Invoke;\n"
+ " void *FuncPtr;\n"
"};\n"
"enum {\n"
- " HAS_NONPOD = (1<<25),\n"
- " HAS_BYREF = (1<<26)\n"
+ " BLOCK_HAS_COPY_DISPOSE = (1<<25),\n"
+ " BLOCK_IS_GLOBAL = (1<<28)\n"
"};\n"
- "#define CLOSURE_IMPL\n"
+ "#define BLOCK_IMPL\n"
"#endif\n";
if (IsHeader) {
// insert the whole string when rewriting a header file
@@ -243,7 +243,7 @@
const char *endBuf = SM->getCharacterData(LocEnd);
const char *methodPtr = startBuf;
- std::string Tag = "struct __closure_impl *";
+ std::string Tag = "struct __block_impl *";
while (*methodPtr++ && (methodPtr != endBuf)) {
switch (*methodPtr) {
@@ -405,7 +405,7 @@
// };
//
if (isBlockPointerType((*I)->getType()))
- S += "struct __closure_impl *";
+ S += "struct __block_impl *";
else
(*I)->getType().getAsStringInternal(Name);
S += Name + " = __cself->" + (*I)->getName() + "; // bound by copy\n";
@@ -471,7 +471,7 @@
std::string RewriteBlocks::SynthesizeBlockImpl(BlockExpr *CE,
std::string Tag) {
- std::string S = Tag + " {\n struct __closure_impl impl;\n";
+ std::string S = Tag + " {\n struct __block_impl impl;\n";
GetBlockDeclRefExprs(CE);
if (BlockDeclRefs.size()) {
@@ -500,7 +500,7 @@
// };
//
if (isBlockPointerType((*I)->getType()))
- S += "struct __closure_impl *";
+ S += "struct __block_impl *";
else
(*I)->getType().getAsStringInternal(Name);
S += Name + ";\n";
@@ -511,7 +511,7 @@
S += " ";
std::string Name = (*I)->getName();
if (isBlockPointerType((*I)->getType()))
- S += "struct __closure_impl *";
+ S += "struct __block_impl *";
else
Context->getPointerType((*I)->getType()).getAsStringInternal(Name);
S += Name + "; // by ref\n";
@@ -702,7 +702,7 @@
// Synthesize the cast.
BlockCall += "(" + Exp->getType().getAsString() + "(*)";
- BlockCall += "(struct __closure_impl *";
+ BlockCall += "(struct __block_impl *";
if (FTP) {
for (FunctionTypeProto::arg_type_iterator I = FTP->arg_type_begin(),
E = FTP->arg_type_end(); I && (I != E); ++I)
@@ -755,7 +755,7 @@
const char *topLevelCommaCursor = 0;
const char *argPtr = startArgList;
bool scannedBlockDecl = false;
- std::string Tag = "struct __closure_impl *";
+ std::string Tag = "struct __block_impl *";
while (*argPtr++ && parenCount) {
switch (*argPtr) {
@@ -925,7 +925,7 @@
// Rewrite the closure block with a compound literal. The first cast is
// to prevent warnings from the C compiler.
- std::string Init = "(struct __closure_impl *)&(" + Tag + "){{0,";
+ std::string Init = "(struct __block_impl *)&(" + Tag + "){{0,";
// Initialize the Flags, Size, and Invoke fields.
Init += (haveByRefDecls ? "HAS_BYREF," : "0,");
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=56955&r1=56954&r2=56955&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct 2 12:12:56 2008
@@ -1286,6 +1286,10 @@
if (Init->getType()->isFunctionType())
return false;
+ // Allow block exprs at top level.
+ if (Init->getType()->isBlockPointerType())
+ return false;
+
Diag(Init->getExprLoc(), diag::err_init_element_not_constant,
Init->getSourceRange());
return true;
Modified: cfe/trunk/test/Sema/block-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-literal.c?rev=56955&r1=56954&r2=56955&view=diff
==============================================================================
--- cfe/trunk/test/Sema/block-literal.c (original)
+++ cfe/trunk/test/Sema/block-literal.c Thu Oct 2 12:12:56 2008
@@ -78,6 +78,9 @@
(1 ? c : c)('x');
}
+static int global_x = 10;
+void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); };
+
#if 0
// Old syntax. FIXME: convert/test.
void test_byref() {
More information about the cfe-commits
mailing list