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
diff --git a/lib/Rewrite/RewriteModernObjC.cpp b/lib/Rewrite/RewriteModernObjC.cpp
index b406adc..c4b0e5e 100644
--- a/lib/Rewrite/RewriteModernObjC.cpp
+++ b/lib/Rewrite/RewriteModernObjC.cpp
@@ -74,6 +74,7 @@
TypeDecl *ProtocolTypeDecl;
VarDecl *GlobalVarDecl;
unsigned RewriteFailedDiag;
+ unsigned GlobalBlockRewriteFailedDiag;
// ObjC string constant support.
unsigned NumObjCStringLiterals;
VarDecl *ConstantStringClassReference;
@@ -572,6 +573,11 @@
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 @@
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 be9c06f..c618f3e 100644
--- a/test/Rewriter/rewrite-block-literal.c
+++ b/test/Rewriter/rewrite-block-literal.c
@@ -71,7 +71,7 @@
}
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);