From: Fariborz Jahanian Date: Thu, 22 Mar 2012 19:54:39 +0000 (+0000) Subject: modern objc rewriter: until we can translate block literals X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d13c2c291f9fec2ed0e12a65f1638710ca979bb0;p=clang 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 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 &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);