[cfe-commits] r153271 - in /cfe/trunk: lib/Rewrite/RewriteModernObjC.cpp test/Rewriter/rewrite-block-literal.c

Fariborz Jahanian fjahanian at apple.com
Thu Mar 22 12:54:40 PDT 2012


Author: fjahanian
Date: Thu Mar 22 14:54:39 2012
New Revision: 153271

URL: http://llvm.org/viewvc/llvm-project?rev=153271&view=rev
Log:
modern objc rewriter: until we can translate block literals
at global scope properly, issue diagnostics.

Modified:
    cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
    cfe/trunk/test/Rewriter/rewrite-block-literal.c

Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=153271&r1=153270&r2=153271&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Thu Mar 22 14:54:39 2012
@@ -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);

Modified: cfe/trunk/test/Rewriter/rewrite-block-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-block-literal.c?rev=153271&r1=153270&r2=153271&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-block-literal.c (original)
+++ cfe/trunk/test/Rewriter/rewrite-block-literal.c Thu Mar 22 14:54:39 2012
@@ -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);
 





More information about the cfe-commits mailing list