When DAE drops the varargs part of a function, ensure any
authorDuncan Sands <baldrick@free.fr>
Fri, 11 Jan 2008 23:13:45 +0000 (23:13 +0000)
committerDuncan Sands <baldrick@free.fr>
Fri, 11 Jan 2008 23:13:45 +0000 (23:13 +0000)
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
test/Transforms/DeadArgElim/2007-12-20-ParamAttrs.ll

index 3550d7135250fa5701ca9f4518aebec515ce3c59..b8770121eb0fba424a2265022235df316937d841 100644 (file)
@@ -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<InvokeInst>(Call)) {
       New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
                            Args.begin(), Args.end(), "", Call);
       cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
-      cast<InvokeInst>(New)->setParamAttrs(CS.getParamAttrs());
+      cast<InvokeInst>(New)->setParamAttrs(PAL);
     } else {
       New = new CallInst(NF, Args.begin(), Args.end(), "", Call);
       cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
-      cast<CallInst>(New)->setParamAttrs(CS.getParamAttrs());
+      cast<CallInst>(New)->setParamAttrs(PAL);
       if (cast<CallInst>(Call)->isTailCall())
         cast<CallInst>(New)->setTailCall();
     }
index 94181f3dbff9800905907637932a76a269f459cc..bd30942633d23a72201f0a3b7953fb0e1c0336c8 100644 (file)
@@ -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
 }