]> granicus.if.org Git - clang/commitdiff
Have __func__ and siblings point to block's implementation function
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 28 Jun 2010 18:58:34 +0000 (18:58 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 28 Jun 2010 18:58:34 +0000 (18:58 +0000)
name. Fixes radar 7860965.

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

lib/CodeGen/CGBlocks.cpp
test/CodeGen/func-in-block.c [new file with mode: 0644]

index d5fc993c797d711629c2dc4845df9e6440ebf9fa..5743aa0d71f7014e41e3372bc43653ca9ce88c9b 100644 (file)
@@ -840,11 +840,22 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, const BlockExpr *BExpr,
 
   CGM.SetInternalFunctionAttributes(BD, Fn, FI);
 
+  QualType FnType(BlockFunctionType, 0);
+  bool HasPrototype = (dyn_cast<FunctionProtoType>(BlockFunctionType) != 0);
+  
+  IdentifierInfo *ID = &getContext().Idents.get(Name.getString());
+  CurCodeDecl = FunctionDecl::Create(getContext(),
+                                     getContext().getTranslationUnitDecl(),
+                                     SourceLocation(), ID, FnType, 
+                                     0,
+                                     FunctionDecl::Static,
+                                     FunctionDecl::None,
+                                     false, HasPrototype);
+  
   StartFunction(BD, ResultType, Fn, Args,
                 BExpr->getBody()->getLocEnd());
 
   CurFuncDecl = OuterFuncDecl;
-  CurCodeDecl = BD;
 
   // If we have a C++ 'this' reference, go ahead and force it into
   // existence now.
diff --git a/test/CodeGen/func-in-block.c b/test/CodeGen/func-in-block.c
new file mode 100644 (file)
index 0000000..27e0c09
--- /dev/null
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fblocks -emit-llvm -o - %s | FileCheck %s
+// rdar: // 7860965
+
+extern void PRINTF(const char *);
+extern void B(void (^)(void));
+
+int main()
+{
+    PRINTF(__func__);
+    B(
+       ^{
+            PRINTF(__func__);
+        }
+    );
+    return 0; // not reached
+}
+
+// CHECK: call void @PRINTF({{.*}}@__func__.__main_block_invoke_