Skip to content

SimplifyCFG: General jump threading needs to update all available values when updating SSA #31182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/SILOptimizer/Utils/BasicBlockOptUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ bool SinkAddressProjections::analyzeAddressProjections(SILInstruction *inst) {
return false;

for (SILValue operandVal : projections[idx]->getOperandValues())
pushOperandVal(operandVal);
if (!pushOperandVal(operandVal))
return false;
}
return true;
}
Expand Down
57 changes: 57 additions & 0 deletions test/SILOptimizer/simplify_cfg_jump_thread_crash.sil
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,60 @@ bb9(%29 : $Optional<AA>):

}

enum FakeOptional<T> {
case some(T)
case none
}

struct S {
}

struct T {
let s: S
}

class C {
func method() -> Any
func f() -> FakeOptional<T>
}

// This test used to crash because we were not properly updating SSA.

sil hidden @dont_crash : $@convention(method) (@guaranteed C) -> @out Any {
bb0(%0 : $*Any, %1 : $C):
%3 = class_method %1 : $C, #C.f : (C) -> () -> FakeOptional<T>, $@convention(method) (@guaranteed C) -> FakeOptional<T>
%4 = apply %3(%1) : $@convention(method) (@guaranteed C) -> FakeOptional<T>
switch_enum %4 : $FakeOptional<T>, case #FakeOptional.some!enumelt: bb1, case #FakeOptional.none!enumelt: bb2

bb1:
%7 = integer_literal $Builtin.Int64, 1
%8 = struct $Int64 (%7 : $Builtin.Int64)
%9 = enum $FakeOptional<Int64>, #FakeOptional.some!enumelt, %8 : $Int64
br bb3(%9 : $FakeOptional<Int64>)

bb2:
%11 = enum $FakeOptional<Int64>, #FakeOptional.none!enumelt
br bb3(%11 : $FakeOptional<Int64>)

bb3(%13 : $FakeOptional<Int64>):
%15 = init_existential_addr %0 : $*Any, $(FakeOptional<Int64>, FakeOptional<S>)
%16 = tuple_element_addr %15 : $*(FakeOptional<Int64>, FakeOptional<S>), 0
%17 = tuple_element_addr %15 : $*(FakeOptional<Int64>, FakeOptional<S>), 1
store %13 to %16 : $*FakeOptional<Int64>
switch_enum %4 : $FakeOptional<T>, case #FakeOptional.some!enumelt: bb4, case #FakeOptional.none!enumelt: bb6

bb4(%20 : $T):
%21 = struct_extract %20 : $T, #T.s
%22 = enum $FakeOptional<S>, #FakeOptional.some!enumelt, %21 : $S
store %22 to %17 : $*FakeOptional<S>
br bb5

bb5:
%25 = tuple ()
return %25 : $()

bb6:
%27 = enum $FakeOptional<S>, #FakeOptional.none!enumelt
store %27 to %17 : $*FakeOptional<S>
br bb5
}