summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/InlineFunction.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <florian.hahn@arm.com>2018-01-06 20:46:00 +0000
committerFlorian Hahn <florian.hahn@arm.com>2018-01-06 20:46:00 +0000
commitde10e6e064e822f6d6bc0d25339b499af21d6be9 (patch)
treee4039cac690e55dcf20f2e226bf237b08cdd88e1 /llvm/lib/Transforms/Utils/InlineFunction.cpp
parent0b93cd7351789911dd13c4f3bfa472be57f4e414 (diff)
downloadbcm5719-llvm-de10e6e064e822f6d6bc0d25339b499af21d6be9.tar.gz
bcm5719-llvm-de10e6e064e822f6d6bc0d25339b499af21d6be9.zip
[InlineFunction] Preserve attributes when forwarding VarArgs.
Reviewers: rnk, efriedma Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D41555 llvm-svn: 321942
Diffstat (limited to 'llvm/lib/Transforms/Utils/InlineFunction.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/InlineFunction.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 20905849441..5574a3d2687 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1811,9 +1811,12 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
}
SmallVector<Value*,4> VarArgsToForward;
+ SmallVector<AttributeSet, 4> VarArgsAttrs;
for (unsigned i = CalledFunc->getFunctionType()->getNumParams();
- i < CS.getNumArgOperands(); i++)
+ i < CS.getNumArgOperands(); i++) {
VarArgsToForward.push_back(CS.getArgOperand(i));
+ VarArgsAttrs.push_back(CS.getAttributes().getParamAttributes(i));
+ }
bool InlinedMustTailCalls = false, InlinedDeoptimizeCalls = false;
if (InlinedFunctionInfo.ContainsCalls) {
@@ -1835,15 +1838,31 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
((ForwardVarArgsTo &&
CI->getCalledFunction() == ForwardVarArgsTo) ||
CI->isMustTailCall())) {
+ // Collect attributes for non-vararg parameters.
+ AttributeList Attrs = CI->getAttributes();
+ SmallVector<AttributeSet, 8> ArgAttrs;
+ if (!Attrs.isEmpty()) {
+ for (unsigned ArgNo = 0;
+ ArgNo < CI->getFunctionType()->getNumParams(); ++ArgNo)
+ ArgAttrs.push_back(Attrs.getParamAttributes(ArgNo));
+ }
+
+ // Add VarArg attributes.
+ ArgAttrs.append(VarArgsAttrs.begin(), VarArgsAttrs.end());
+ Attrs = AttributeList::get(CI->getContext(), Attrs.getFnAttributes(),
+ Attrs.getRetAttributes(), ArgAttrs);
+ // Add VarArgs to existing parameters.
SmallVector<Value *, 6> Params(CI->arg_operands());
Params.append(VarArgsToForward.begin(), VarArgsToForward.end());
- CallInst *Call =
+ CallInst *NewCI =
CallInst::Create(CI->getCalledFunction() ? CI->getCalledFunction()
: CI->getCalledValue(),
Params, "", CI);
- Call->setDebugLoc(CI->getDebugLoc());
- CI->replaceAllUsesWith(Call);
+ NewCI->setDebugLoc(CI->getDebugLoc());
+ NewCI->setAttributes(Attrs);
+ CI->replaceAllUsesWith(NewCI);
CI->eraseFromParent();
+ CI = NewCI;
}
if (Function *F = CI->getCalledFunction())
OpenPOWER on IntegriCloud