summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2018-03-26 09:44:24 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2018-03-26 09:44:24 +0000
commit8840f644b40b4f764ff5cd297d454429a2fd63c5 (patch)
tree21aca126761140f6df815a03c0dd4ee5f97cb1d1
parent53a423a41702c6d8dca9a5eff9c0c034a5492a9b (diff)
downloadbcm5719-llvm-8840f644b40b4f764ff5cd297d454429a2fd63c5.tar.gz
bcm5719-llvm-8840f644b40b4f764ff5cd297d454429a2fd63c5.zip
[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. llvm-svn: 328481
-rw-r--r--llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp8
-rw-r--r--llvm/test/Transforms/DeadArgElim/allocsize.ll13
2 files changed, 19 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
index 78a2227cde9..3a86c88c98f 100644
--- a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -837,10 +837,14 @@ bool DeadArgumentEliminationPass::RemoveDeadStuffFromFunction(Function *F) {
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());
diff --git a/llvm/test/Transforms/DeadArgElim/allocsize.ll b/llvm/test/Transforms/DeadArgElim/allocsize.ll
new file mode 100644
index 00000000000..eee55f09dc7
--- /dev/null
+++ b/llvm/test/Transforms/DeadArgElim/allocsize.ll
@@ -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
+}
OpenPOWER on IntegriCloud