[llvm] r329868 - [DeadArgElim] Remove allocsize attributes on callsites

George Burgess IV via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 11 19:06:01 PDT 2018


Author: gbiv
Date: Wed Apr 11 19:06:01 2018
New Revision: 329868

URL: http://llvm.org/viewvc/llvm-project?rev=329868&view=rev
Log:
[DeadArgElim] Remove allocsize attributes on callsites

We're already removing allocsize attributes from Functions that we
remove args from, since removing arguments from a function may make the
allocsize attribute incorrect. It appears we forgot to also remove them
from callsites.

Without this, I get verifier errors on `@Test2`.

It probably wouldn't be too hard to make DAE properly update allocsize
attributes instead of dropping them, but I can't think of a scenario
where that'd be useful in practice.

Modified:
    llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp
    llvm/trunk/test/Transforms/DeadArgElim/allocsize.ll

Modified: llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp?rev=329868&r1=329867&r2=329868&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp Wed Apr 11 19:06:01 2018
@@ -916,8 +916,14 @@ bool DeadArgumentEliminationPass::Remove
 
     // 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<OperandBundleDef, 1> OpBundles;
     CS.getOperandBundlesAsDefs(OpBundles);

Modified: llvm/trunk/test/Transforms/DeadArgElim/allocsize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DeadArgElim/allocsize.ll?rev=329868&r1=329867&r2=329868&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/DeadArgElim/allocsize.ll (original)
+++ llvm/trunk/test/Transforms/DeadArgElim/allocsize.ll Wed Apr 11 19:06:01 2018
@@ -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
+}




More information about the llvm-commits mailing list