[llvm] ce08177 - [FlattenCFG] avoid crash on malformed code
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 16 12:11:06 PDT 2022
Author: Sanjay Patel
Date: 2022-08-16T15:11:00-04:00
New Revision: ce081776b298b0c85fa24f3bc149106f24b096a4
URL: https://github.com/llvm/llvm-project/commit/ce081776b298b0c85fa24f3bc149106f24b096a4
DIFF: https://github.com/llvm/llvm-project/commit/ce081776b298b0c85fa24f3bc149106f24b096a4.diff
LOG: [FlattenCFG] avoid crash on malformed code
We don't have a dominator tree in this pass, so we
can't bail out sooner by checking for unreachable
code, but this is a minimal fix for the example in
issue #56875.
Added:
Modified:
llvm/lib/Transforms/Utils/FlattenCFG.cpp
llvm/test/Transforms/Util/flattencfg.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/FlattenCFG.cpp b/llvm/lib/Transforms/Utils/FlattenCFG.cpp
index ddd3f597ae019..89823ed1c831a 100644
--- a/llvm/lib/Transforms/Utils/FlattenCFG.cpp
+++ b/llvm/lib/Transforms/Utils/FlattenCFG.cpp
@@ -431,6 +431,9 @@ bool FlattenCFGOpt::MergeIfRegion(BasicBlock *BB, IRBuilder<> &Builder) {
return false;
BasicBlock *FirstEntryBlock = CInst1->getParent();
+ // Don't die trying to process degenerate/unreachable code.
+ if (FirstEntryBlock == SecondEntryBlock)
+ return false;
// Either then-path or else-path should be empty.
bool InvertCond2 = false;
diff --git a/llvm/test/Transforms/Util/flattencfg.ll b/llvm/test/Transforms/Util/flattencfg.ll
index e94e0cdc939df..3e598ee7c9cbc 100644
--- a/llvm/test/Transforms/Util/flattencfg.ll
+++ b/llvm/test/Transforms/Util/flattencfg.ll
@@ -216,3 +216,20 @@ if.else.y:
exit:
ret void
}
+
+; This would crash.
+
+declare i1 @llvm.smax.i1(i1, i1) #0
+
+; CHECK-LABEL: @PR56875
+define void @PR56875(i1 %val_i1_5) {
+entry_1:
+ ret void
+
+bb_2: ; preds = %bb_4
+ br label %bb_4
+
+bb_4: ; preds = %bb_4, %bb_2
+ %val_i1_46 = call i1 @llvm.smax.i1(i1 %val_i1_5, i1 %val_i1_5)
+ br i1 %val_i1_46, label %bb_4, label %bb_2
+}
More information about the llvm-commits
mailing list