[llvm-commits] [llvm] r166291 - in /llvm/trunk: lib/Transforms/Scalar/IndVarSimplify.cpp test/Transforms/IndVarSimplify/crash.ll
Benjamin Kramer
benny.kra at googlemail.com
Fri Oct 19 10:53:54 PDT 2012
Author: d0k
Date: Fri Oct 19 12:53:54 2012
New Revision: 166291
URL: http://llvm.org/viewvc/llvm-project?rev=166291&view=rev
Log:
Indvars: Don't recursively delete instruction during BB iteration.
This can invalidate the iterators leading to use after frees and crashes.
Fixes PR12536.
Modified:
llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
llvm/trunk/test/Transforms/IndVarSimplify/crash.ll
Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=166291&r1=166290&r2=166291&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Fri Oct 19 12:53:54 2012
@@ -551,15 +551,17 @@
PN->setIncomingValue(i, ExitVal);
- // If this instruction is dead now, delete it.
- RecursivelyDeleteTriviallyDeadInstructions(Inst, TLI);
+ // If this instruction is dead now, delete it. Don't do it now to avoid
+ // invalidating iterators.
+ if (isInstructionTriviallyDead(Inst, TLI))
+ DeadInsts.push_back(Inst);
if (NumPreds == 1) {
// Completely replace a single-pred PHI. This is safe, because the
// NewVal won't be variant in the loop, so we don't need an LCSSA phi
// node anymore.
PN->replaceAllUsesWith(ExitVal);
- RecursivelyDeleteTriviallyDeadInstructions(PN, TLI);
+ PN->eraseFromParent();
}
}
if (NumPreds != 1) {
Modified: llvm/trunk/test/Transforms/IndVarSimplify/crash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/crash.ll?rev=166291&r1=166290&r2=166291&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/crash.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/crash.ll Fri Oct 19 12:53:54 2012
@@ -113,3 +113,21 @@
ret void
}
+; PR12536
+define void @fn1() noreturn nounwind {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.end, %entry
+ %b.0 = phi i32 [ undef, %entry ], [ %conv, %for.end ]
+ br label %for.cond1
+
+for.cond1: ; preds = %for.cond1, %for.cond
+ %c.0 = phi i32 [ %b.0, %for.cond1 ], [ 0, %for.cond ]
+ br i1 undef, label %for.cond1, label %for.end
+
+for.end: ; preds = %for.cond1
+ %cmp2 = icmp slt i32 %c.0, 1
+ %conv = zext i1 %cmp2 to i32
+ br label %for.cond
+}
More information about the llvm-commits
mailing list