aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-03-22 19:54:39 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-03-22 19:54:39 +0000
commitd13c2c291f9fec2ed0e12a65f1638710ca979bb0 (patch)
tree6e1df1771834096d52301f10a99d711105af0852
parent0d4cb85130d91da61c45aecb9fd31c7097a7cfcc (diff)
modern objc rewriter: until we can translate block literals
at global scope properly, issue diagnostics. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153271 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Rewrite/RewriteModernObjC.cpp11
-rw-r--r--test/Rewriter/rewrite-block-literal.c2
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/Rewrite/RewriteModernObjC.cpp b/lib/Rewrite/RewriteModernObjC.cpp
index b406adcf51..c4b0e5e48e 100644
--- a/lib/Rewrite/RewriteModernObjC.cpp
+++ b/lib/Rewrite/RewriteModernObjC.cpp
@@ -74,6 +74,7 @@ namespace {
TypeDecl *ProtocolTypeDecl;
VarDecl *GlobalVarDecl;
unsigned RewriteFailedDiag;
+ unsigned GlobalBlockRewriteFailedDiag;
// ObjC string constant support.
unsigned NumObjCStringLiterals;
VarDecl *ConstantStringClassReference;
@@ -572,6 +573,11 @@ RewriteModernObjC::RewriteModernObjC(std::string inFile, raw_ostream* OS,
IsHeader = IsHeaderFile(inFile);
RewriteFailedDiag = Diags.getCustomDiagID(DiagnosticsEngine::Warning,
"rewriting sub-expression within a macro (may not be correct)");
+ // FIXME. This should be an error. But if block is not called, it is OK. And it
+ // may break including some headers.
+ GlobalBlockRewriteFailedDiag = Diags.getCustomDiagID(DiagnosticsEngine::Warning,
+ "rewriting block literal declared in global scope is not implemented");
+
TryFinallyContainsReturnDiag = Diags.getCustomDiagID(
DiagnosticsEngine::Warning,
"rewriter doesn't support user-specified control flow semantics "
@@ -4409,7 +4415,12 @@ FunctionDecl *RewriteModernObjC::SynthBlockInitFunctionDecl(StringRef name) {
Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,
const SmallVector<DeclRefExpr *, 8> &InnerBlockDeclRefs) {
+
const BlockDecl *block = Exp->getBlockDecl();
+
+ if (block->getDeclContext()->getRedeclContext()->isFileContext())
+ Diags.Report(block->getLocation(), GlobalBlockRewriteFailedDiag);
+
Blocks.push_back(Exp);
CollectBlockDeclRefInfo(Exp);
diff --git a/test/Rewriter/rewrite-block-literal.c b/test/Rewriter/rewrite-block-literal.c
index be9c06f7db..c618f3e39e 100644
--- a/test/Rewriter/rewrite-block-literal.c
+++ b/test/Rewriter/rewrite-block-literal.c
@@ -71,7 +71,7 @@ void test_arguments() {
}
static int global_x = 10;
-void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); };
+void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); }; // expected-warning {{rewriting block literal declared in global scope is not implemented}}
typedef void (^void_block_t)(void);