diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2008-06-01 15:54:49 +0000 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2008-06-01 15:54:49 +0000 |
| commit | ff4a2d9e2c1ddbf87e00e2a36ae341faf03eafb3 (patch) | |
| tree | 6e1b1bf570ee44a2fc81c486d5e50e4fc97c88ca /lib/CodeGen/CGExpr.cpp | |
| parent | 7dfa639e9274b9f40c8f207e35c0fcbfe75d04f8 (diff) | |
First cut at setting attributes for functions and calls; this puts us
much closer to passing the gcc struct layout tests.
It might be possible to refactor this a bit, but I'm not sure there's
actually enough common code for that to be useful.
To get the calling convention completely correct, a bit of
platform-specific code is necessary even for x86-Linux. On x86-Linux, the
alignment of function parameters is extremely strange; as far as I can tell,
it's always 4 except for SSE vectors or structs containing SSE vectors. I'm
continuing to investigate this.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51839 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
| -rw-r--r-- | lib/CodeGen/CGExpr.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 8c867d9437..d960503e57 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -711,6 +711,29 @@ RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType, } llvm::CallInst *CI = Builder.CreateCall(Callee,&Args[0],&Args[0]+Args.size()); + + // Note that there is parallel code in SetFunctionAttributes in CodeGenModule + llvm::SmallVector<llvm::ParamAttrsWithIndex, 8> ParamAttrList; + if (hasAggregateLLVMType(ResultType)) + ParamAttrList.push_back( + llvm::ParamAttrsWithIndex::get(1, llvm::ParamAttr::StructRet)); + unsigned increment = hasAggregateLLVMType(ResultType) ? 2 : 1; + for (unsigned i = 0; i < NumArgs; i++) { + QualType ParamType = ArgExprs[i]->getType(); + unsigned ParamAttrs = 0; + if (ParamType->isRecordType()) + ParamAttrs |= llvm::ParamAttr::ByVal; + if (ParamType->isSignedIntegerType() && ParamType->isPromotableIntegerType()) + ParamAttrs |= llvm::ParamAttr::SExt; + if (ParamType->isUnsignedIntegerType() && ParamType->isPromotableIntegerType()) + ParamAttrs |= llvm::ParamAttr::ZExt; + if (ParamAttrs) + ParamAttrList.push_back(llvm::ParamAttrsWithIndex::get(i + increment, + ParamAttrs)); + } + CI->setParamAttrs(llvm::PAListPtr::get(ParamAttrList.begin(), + ParamAttrList.size())); + if (const llvm::Function *F = dyn_cast<llvm::Function>(Callee)) CI->setCallingConv(F->getCallingConv()); if (CI->getType() != llvm::Type::VoidTy) |
