]> granicus.if.org Git - clang/commitdiff
Make use of __func__ in a block actually refer to
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 13 Aug 2010 00:19:55 +0000 (00:19 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 13 Aug 2010 00:19:55 +0000 (00:19 +0000)
block's helper function. Fixes radar 7860965.

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

lib/CodeGen/CGBlocks.cpp
test/CodeGen/func-in-block.c

index bb81bf56b5f017b6ab36cc27fbe210a8e98bd718..1dceb32a5ce874afd0cdce7ccaa006361de75e71 100644 (file)
@@ -790,7 +790,11 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, const BlockExpr *BExpr,
                            Name.getString(), &CGM.getModule());
 
   CGM.SetInternalFunctionAttributes(BD, Fn, FI);
-
+  StartFunction(BD, ResultType, Fn, Args,
+                BExpr->getBody()->getLocEnd());
+  
+  CurFuncDecl = OuterFuncDecl;
+  
   QualType FnType(BlockFunctionType, 0);
   bool HasPrototype = isa<FunctionProtoType>(BlockFunctionType);
   
@@ -802,12 +806,19 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, const BlockExpr *BExpr,
                                      FunctionDecl::Static,
                                      FunctionDecl::None,
                                      false, HasPrototype);
+  if (FunctionProtoType *FT = dyn_cast<FunctionProtoType>(FnType)) {
+    const FunctionDecl *CFD = dyn_cast<FunctionDecl>(CurCodeDecl);
+    FunctionDecl *FD = const_cast<FunctionDecl *>(CFD);
+    llvm::SmallVector<ParmVarDecl*, 16> Params;
+    for (unsigned i = 0, e = FT->getNumArgs(); i != e; ++i)
+      Params.push_back(ParmVarDecl::Create(getContext(), FD, 
+                                           SourceLocation(), 0,
+                                           FT->getArgType(i), /*TInfo=*/0,
+                                           VarDecl::None, VarDecl::None, 0));
+    FD->setParams(Params.data(), Params.size());
+  }
+  
   
-  StartFunction(BD, ResultType, Fn, Args,
-                BExpr->getBody()->getLocEnd());
-
-  CurFuncDecl = OuterFuncDecl;
-
   // If we have a C++ 'this' reference, go ahead and force it into
   // existence now.
   if (Info.CXXThisRef) {
index 27e0c09609973579740b731edf618a7b6e054f04..7e65ff92df0578feda64acb2c60bb791e3c6f53c 100644 (file)
@@ -15,4 +15,5 @@ int main()
     return 0; // not reached
 }
 
+// CHECK: @__func__.__main_block_invoke_0 = private constant [22 x i8] c"__main_block_invoke_0\00"
 // CHECK: call void @PRINTF({{.*}}@__func__.__main_block_invoke_