From: Daniel Dunbar Date: Fri, 17 Apr 2009 00:48:04 +0000 (+0000) Subject: Attributes on block functions were not being set. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e4f40e1bbc4dce16bbb9870300a435419f1b3d5;p=clang Attributes on block functions were not being set. - clang not producing correct large struct return code for Blocks git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69337 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 7a8cd0d822..27b60a01e9 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -670,6 +670,8 @@ CodeGenFunction::GenerateBlockFunction(const BlockExpr *BExpr, Name, &CGM.getModule()); + CGM.SetInternalFunctionAttributes(BD, Fn, FI); + StartFunction(BD, ResultType, Fn, Args, BExpr->getBody()->getLocEnd()); CurFuncDecl = OuterFuncDecl; diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index 4423217c7d..808add74f7 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -109,7 +109,8 @@ void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD, FunctionArgList Args; llvm::Function *Fn = CGM.getObjCRuntime().GenerateMethod(OMD, CD); - CGM.SetMethodAttributes(OMD, Fn); + const CGFunctionInfo &FI = CGM.getTypes().getFunctionInfo(OMD); + CGM.SetInternalFunctionAttributes(OMD, Fn, FI); Args.push_back(std::make_pair(OMD->getSelfDecl(), OMD->getSelfDecl()->getType())); diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index d1d67a11b8..7cb5e43cb5 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -340,14 +340,15 @@ void CodeGenModule::SetCommonAttributes(const Decl *D, GV->setSection(SA->getName()); } -void CodeGenModule::SetMethodAttributes(const ObjCMethodDecl *MD, - llvm::Function *F) { - SetLLVMFunctionAttributes(MD, getTypes().getFunctionInfo(MD), F); - SetLLVMFunctionAttributesForDefinition(MD, F); +void CodeGenModule::SetInternalFunctionAttributes(const Decl *D, + llvm::Function *F, + const CGFunctionInfo &FI) { + SetLLVMFunctionAttributes(D, FI, F); + SetLLVMFunctionAttributesForDefinition(D, F); F->setLinkage(llvm::Function::InternalLinkage); - SetCommonAttributes(MD, F); + SetCommonAttributes(D, F); } void CodeGenModule::SetFunctionAttributes(const FunctionDecl *FD, diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 17a9a9f907..469c637e2d 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -303,8 +303,12 @@ public: void ErrorUnsupported(const Decl *D, const char *Type, bool OmitOnError=false); - void SetMethodAttributes(const ObjCMethodDecl *MD, - llvm::Function *F); + /// SetInternalFunctionAttributes - Set the attributes on the LLVM + /// function for the given decl and function info. This applies + /// attributes necessary for handling the ABI as well as user + /// specified attributes like section. + void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F, + const CGFunctionInfo &FI); /// SetLLVMFunctionAttributes - Set the LLVM function attributes /// (sext, zext, etc). diff --git a/test/CodeGen/blocks.c b/test/CodeGen/blocks.c index 3eb4c43505..4203fce051 100644 --- a/test/CodeGen/blocks.c +++ b/test/CodeGen/blocks.c @@ -1,7 +1,20 @@ -// RUN: clang-cc %s -emit-llvm -o %t -fblocks +// RUN: clang-cc -triple i386-unknown-unknown %s -emit-llvm -o %t -fblocks && void (^f)(void) = ^{}; // rdar://6768379 int f0(int (^a0)()) { return a0(1, 2, 3); } + +// Verify that attributes on blocks are set correctly. +typedef struct s0 T; +struct s0 { + int a[64]; +}; + +// RUN: grep 'internal void @__f2_block_invoke_(.struct.s0\* noalias sret .*, .*, .* byval .*)' %t && +struct s0 f2(struct s0 a0) { + return ^(struct s0 a1){ return a1; }(a0); +} + +// RUN: true