diff --git a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp index 0c54b7fc9306..4ef8e4b509a3 100644 --- a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -916,8 +916,14 @@ bool DeadArgumentEliminationPass::RemoveDeadStuffFromFunction(Function *F) { // Reconstruct the AttributesList based on the vector we constructed. assert(ArgAttrVec.size() == Args.size()); + + // Again, be sure to remove any allocsize attributes, since their indices + // may now be incorrect. + AttributeSet FnAttrs = CallPAL.getFnAttributes().removeAttribute( + F->getContext(), Attribute::AllocSize); + AttributeList NewCallPAL = AttributeList::get( - F->getContext(), CallPAL.getFnAttributes(), RetAttrs, ArgAttrVec); + F->getContext(), FnAttrs, RetAttrs, ArgAttrVec); SmallVector OpBundles; CS.getOperandBundlesAsDefs(OpBundles); diff --git a/llvm/test/Transforms/DeadArgElim/allocsize.ll b/llvm/test/Transforms/DeadArgElim/allocsize.ll index eee55f09dc78..04c1f533eaa2 100644 --- a/llvm/test/Transforms/DeadArgElim/allocsize.ll +++ b/llvm/test/Transforms/DeadArgElim/allocsize.ll @@ -11,3 +11,8 @@ define i64 @NeedsArg(i64 %s) { %c = call i64 @MagickMallocAligned(i64 0, i64 %s) ret i64 %c } + +define i64 @Test2(i64 %s) { + %c = call i64 @MagickMallocAligned(i64 0, i64 %s) allocsize(1) + ret i64 %c +}