Skip to content

Commit 249b55b

Browse files
authored
Merge pull request #18939 from eeckstein/fix-cf-crash
2 parents eeb8f33 + 12b6c0a commit 249b55b

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

lib/SILOptimizer/Utils/ConstantFolding.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,12 @@ ConstantFolder::processWorkList() {
16321632
// instructions.
16331633
auto UserV = cast<SingleValueInstruction>(User);
16341634

1635+
// Handle a corner case: if this instruction is an unreachable CFG loop
1636+
// there is no defined dominance order and we can end up with loops in the
1637+
// use-def chain. Just bail in this case.
1638+
if (C == UserV)
1639+
continue;
1640+
16351641
// Ok, we have succeeded. Add user to the FoldedUsers list and perform the
16361642
// necessary cleanups, RAUWs, etc.
16371643
FoldedUsers.insert(User);

test/SILOptimizer/simplify_cfg.sil

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,3 +3047,51 @@ bb3(%res : $Builtin.Int32):
30473047
release_value %pa : $@callee_guaranteed (Builtin.Int32) -> (Builtin.Int32)
30483048
return %res : $Builtin.Int32
30493049
}
3050+
3051+
struct TestStr {
3052+
let a: Int32
3053+
let c: Int32
3054+
}
3055+
3056+
enum TestEnm {
3057+
case X
3058+
case Y(TestStr)
3059+
}
3060+
3061+
// CHECK-LABEL: sil @dont_crash
3062+
// CHECK: bb0(%0 : $TestEnm, %1 : $Int32):
3063+
// CHECK-NEXT: %2 = tuple ()
3064+
// CHECK-NEXT: return %2 : $()
3065+
sil @dont_crash : $@convention(method) (TestEnm, Int32) -> () {
3066+
bb0(%2 : $TestEnm, %3 : $Int32):
3067+
%98 = integer_literal $Builtin.Int1, -1
3068+
cond_br %98, bb2, bb3
3069+
3070+
bb2:
3071+
%18 = tuple()
3072+
return %18 : $()
3073+
3074+
bb3:
3075+
br bb8(%2 : $TestEnm)
3076+
3077+
bb8(%47 : $TestEnm):
3078+
%49 = unchecked_enum_data %47 : $TestEnm, #TestEnm.Y!enumelt.1
3079+
%57 = struct_extract %49 : $TestStr, #TestStr.c
3080+
cond_br undef, bb9, bb11
3081+
3082+
bb9:
3083+
br bb10
3084+
3085+
bb10:
3086+
%64 = struct $TestStr (%3 : $Int32, %57 : $Int32)
3087+
%65 = enum $TestEnm, #TestEnm.Y!enumelt.1, %64 : $TestStr
3088+
cond_br undef, bb2, bb16
3089+
3090+
bb11:
3091+
br bb10
3092+
3093+
3094+
bb16:
3095+
br bb8(%65 : $TestEnm)
3096+
}
3097+

0 commit comments

Comments
 (0)