]> granicus.if.org Git - clang/commitdiff
modern objc rewriter: until we can translate block literals
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 22 Mar 2012 19:54:39 +0000 (19:54 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 22 Mar 2012 19:54:39 +0000 (19:54 +0000)
at global scope properly, issue diagnostics.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153271 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Rewrite/RewriteModernObjC.cpp
test/Rewriter/rewrite-block-literal.c

index b406adcf51814f9389c5521b31fef444a84b31eb..c4b0e5e48ebd4baf3108e1e128720472dd37f783 100644 (file)
@@ -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);
index be9c06f7db2595da11b5a379a1487ff15c9d6d42..c618f3e39e49125bffbb02225502f392f0f9ecd5 100644 (file)
@@ -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);