[llvm] r328481 - [DeadArgElim] Strip allocsize attributes when deleting an argument.

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 26 02:44:24 PDT 2018


Author: d0k
Date: Mon Mar 26 02:44:24 2018
New Revision: 328481

URL: http://llvm.org/viewvc/llvm-project?rev=328481&view=rev
Log:
[DeadArgElim] Strip allocsize attributes when deleting an argument.

Since allocsize refers to the argument number it gets invalidated when
an argument is removed and the numbers shift.

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

Modified: llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp?rev=328481&r1=328480&r2=328481&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp Mon Mar 26 02:44:24 2018
@@ -837,10 +837,14 @@ bool DeadArgumentEliminationPass::Remove
 
   AttributeSet RetAttrs = AttributeSet::get(F->getContext(), RAttrs);
 
+  // Strip allocsize attributes. They might refer to the deleted arguments.
+  AttributeSet FnAttrs = PAL.getFnAttributes().removeAttribute(
+      F->getContext(), Attribute::AllocSize);
+
   // Reconstruct the AttributesList based on the vector we constructed.
   assert(ArgAttrVec.size() == Params.size());
-  AttributeList NewPAL = AttributeList::get(
-      F->getContext(), PAL.getFnAttributes(), RetAttrs, ArgAttrVec);
+  AttributeList NewPAL =
+      AttributeList::get(F->getContext(), FnAttrs, RetAttrs, ArgAttrVec);
 
   // Create the new function type based on the recomputed parameters.
   FunctionType *NFTy = FunctionType::get(NRetTy, Params, FTy->isVarArg());

Added: llvm/trunk/test/Transforms/DeadArgElim/allocsize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DeadArgElim/allocsize.ll?rev=328481&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/DeadArgElim/allocsize.ll (added)
+++ llvm/trunk/test/Transforms/DeadArgElim/allocsize.ll Mon Mar 26 02:44:24 2018
@@ -0,0 +1,13 @@
+; RUN: opt < %s -deadargelim -S | FileCheck %s
+; PR36867
+
+; CHECK-LABEL: @MagickMallocAligned
+; CHECK-NOT: allocsize
+define internal i64 @MagickMallocAligned(i64 %DEADARG1, i64 %s) allocsize(1) {
+        ret i64 %s
+}
+
+define i64 @NeedsArg(i64 %s) {
+	%c = call i64 @MagickMallocAligned(i64 0, i64 %s)
+	ret i64 %c
+}




More information about the llvm-commits mailing list