[llvm] r250922 - [SimplifyCFG] Don't use-after-free an SSA value
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 21 11:22:24 PDT 2015
Author: majnemer
Date: Wed Oct 21 13:22:24 2015
New Revision: 250922
URL: http://llvm.org/viewvc/llvm-project?rev=250922&view=rev
Log:
[SimplifyCFG] Don't use-after-free an SSA value
SimplifyTerminatorOnSelect didn't consider the possibility that the
condition might be related to one of PHI nodes.
This fixes PR25267.
Added:
llvm/trunk/test/Transforms/SimplifyCFG/PR25267.ll
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=250922&r1=250921&r2=250922&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Wed Oct 21 13:22:24 2015
@@ -2571,7 +2571,8 @@ static bool SimplifyTerminatorOnSelect(T
else if (Succ == KeepEdge2)
KeepEdge2 = nullptr;
else
- Succ->removePredecessor(OldTerm->getParent());
+ Succ->removePredecessor(OldTerm->getParent(),
+ /*DontDeleteUselessPHIs=*/true);
}
IRBuilder<> Builder(OldTerm);
Added: llvm/trunk/test/Transforms/SimplifyCFG/PR25267.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/PR25267.ll?rev=250922&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/PR25267.ll (added)
+++ llvm/trunk/test/Transforms/SimplifyCFG/PR25267.ll Wed Oct 21 13:22:24 2015
@@ -0,0 +1,24 @@
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
+
+define void @f() {
+entry:
+ br label %for.cond
+
+for.cond:
+ %phi = phi i1 [ false, %entry ], [ true, %for.body ]
+ %select = select i1 %phi, i32 1, i32 2
+ br label %for.body
+
+for.body:
+ switch i32 %select, label %for.cond [
+ i32 1, label %return
+ i32 2, label %for.body
+ ]
+
+return:
+ ret void
+}
+
+; CHECK-LABEL: define void @f(
+; CHECK: br label %[[LABEL:.*]]
+; CHECK: br label %[[LABEL]]
More information about the llvm-commits
mailing list