Skip to content

Commit 543b35b

Browse files
Merge pull request #31182 from aschwaighofer/jumpthread_fix_61232730
SimplifyCFG: General jump threading needs to update all available values when updating SSA
2 parents 4e0c360 + 3f22bfd commit 543b35b

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

lib/SILOptimizer/Utils/BasicBlockOptUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ bool SinkAddressProjections::analyzeAddressProjections(SILInstruction *inst) {
215215
return false;
216216

217217
for (SILValue operandVal : projections[idx]->getOperandValues())
218-
pushOperandVal(operandVal);
218+
if (!pushOperandVal(operandVal))
219+
return false;
219220
}
220221
return true;
221222
}

test/SILOptimizer/simplify_cfg_jump_thread_crash.sil

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,60 @@ bb9(%29 : $Optional<AA>):
155155

156156
}
157157

158+
enum FakeOptional<T> {
159+
case some(T)
160+
case none
161+
}
162+
163+
struct S {
164+
}
165+
166+
struct T {
167+
let s: S
168+
}
169+
170+
class C {
171+
func method() -> Any
172+
func f() -> FakeOptional<T>
173+
}
174+
175+
// This test used to crash because we were not properly updating SSA.
176+
177+
sil hidden @dont_crash : $@convention(method) (@guaranteed C) -> @out Any {
178+
bb0(%0 : $*Any, %1 : $C):
179+
%3 = class_method %1 : $C, #C.f : (C) -> () -> FakeOptional<T>, $@convention(method) (@guaranteed C) -> FakeOptional<T>
180+
%4 = apply %3(%1) : $@convention(method) (@guaranteed C) -> FakeOptional<T>
181+
switch_enum %4 : $FakeOptional<T>, case #FakeOptional.some!enumelt: bb1, case #FakeOptional.none!enumelt: bb2
182+
183+
bb1:
184+
%7 = integer_literal $Builtin.Int64, 1
185+
%8 = struct $Int64 (%7 : $Builtin.Int64)
186+
%9 = enum $FakeOptional<Int64>, #FakeOptional.some!enumelt, %8 : $Int64
187+
br bb3(%9 : $FakeOptional<Int64>)
188+
189+
bb2:
190+
%11 = enum $FakeOptional<Int64>, #FakeOptional.none!enumelt
191+
br bb3(%11 : $FakeOptional<Int64>)
192+
193+
bb3(%13 : $FakeOptional<Int64>):
194+
%15 = init_existential_addr %0 : $*Any, $(FakeOptional<Int64>, FakeOptional<S>)
195+
%16 = tuple_element_addr %15 : $*(FakeOptional<Int64>, FakeOptional<S>), 0
196+
%17 = tuple_element_addr %15 : $*(FakeOptional<Int64>, FakeOptional<S>), 1
197+
store %13 to %16 : $*FakeOptional<Int64>
198+
switch_enum %4 : $FakeOptional<T>, case #FakeOptional.some!enumelt: bb4, case #FakeOptional.none!enumelt: bb6
199+
200+
bb4(%20 : $T):
201+
%21 = struct_extract %20 : $T, #T.s
202+
%22 = enum $FakeOptional<S>, #FakeOptional.some!enumelt, %21 : $S
203+
store %22 to %17 : $*FakeOptional<S>
204+
br bb5
205+
206+
bb5:
207+
%25 = tuple ()
208+
return %25 : $()
209+
210+
bb6:
211+
%27 = enum $FakeOptional<S>, #FakeOptional.none!enumelt
212+
store %27 to %17 : $*FakeOptional<S>
213+
br bb5
214+
}

0 commit comments

Comments
 (0)