From bfc5ae6df028a455efd24dc0bb223e717e0e3655 Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Fri, 11 Jan 2008 23:13:45 +0000 Subject: [PATCH] When DAE drops the varargs part of a function, ensure any attributes on the vararg call arguments are also dropped. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45892 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/DeadArgumentElimination.cpp | 17 +++++++++++++++-- .../DeadArgElim/2007-12-20-ParamAttrs.ll | 5 ++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp index 3550d713525..b8770121eb0 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -175,16 +175,29 @@ bool DAE::DeleteDeadVarargs(Function &Fn) { // Pass all the same arguments. Args.assign(CS.arg_begin(), CS.arg_begin()+NumArgs); + // Drop any attributes that were on the vararg arguments. + const ParamAttrsList *PAL = CS.getParamAttrs(); + if (PAL && PAL->getParamIndex(PAL->size() - 1) > NumArgs) { + ParamAttrsVector ParamAttrsVec; + for (unsigned i = 0; PAL->getParamIndex(i) <= NumArgs; ++i) { + ParamAttrsWithIndex PAWI; + PAWI = ParamAttrsWithIndex::get(PAL->getParamIndex(i), + PAL->getParamAttrsAtIndex(i)); + ParamAttrsVec.push_back(PAWI); + } + PAL = ParamAttrsList::get(ParamAttrsVec); + } + Instruction *New; if (InvokeInst *II = dyn_cast(Call)) { New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), Args.begin(), Args.end(), "", Call); cast(New)->setCallingConv(CS.getCallingConv()); - cast(New)->setParamAttrs(CS.getParamAttrs()); + cast(New)->setParamAttrs(PAL); } else { New = new CallInst(NF, Args.begin(), Args.end(), "", Call); cast(New)->setCallingConv(CS.getCallingConv()); - cast(New)->setParamAttrs(CS.getParamAttrs()); + cast(New)->setParamAttrs(PAL); if (cast(Call)->isTailCall()) cast(New)->setTailCall(); } diff --git a/test/Transforms/DeadArgElim/2007-12-20-ParamAttrs.ll b/test/Transforms/DeadArgElim/2007-12-20-ParamAttrs.ll index 94181f3dbff..bd30942633d 100644 --- a/test/Transforms/DeadArgElim/2007-12-20-ParamAttrs.ll +++ b/test/Transforms/DeadArgElim/2007-12-20-ParamAttrs.ll @@ -2,6 +2,9 @@ ; RUN: llvm-as < %s | opt -deadargelim | llvm-dis | grep signext | count 2 ; RUN: llvm-as < %s | opt -deadargelim | llvm-dis | not grep inreg ; RUN: llvm-as < %s | opt -deadargelim | llvm-dis | not grep zeroext +; RUN: llvm-as < %s | opt -deadargelim | llvm-dis | not grep byval + + %struct = type { } @g = global i8 0 @@ -11,6 +14,6 @@ define internal i8 @foo(i8* inreg %p, i8 signext %y, ... ) zeroext nounwind { } define i32 @bar() { - %A = call i8(i8*, i8, ...)* @foo(i8* inreg null, i8 signext 1, i8 2) zeroext nounwind + %A = call i8(i8*, i8, ...)* @foo(i8* inreg null, i8 signext 1, %struct* byval null ) zeroext nounwind ret i32 0 } -- 2.34.1