Skip to content

Commit 52c3d70

Browse files
authored
Merge pull request swiftlang#31218 from atrick/comment-simplifycfg-test
2 parents 4619e2e + 6898b03 commit 52c3d70

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

test/SILOptimizer/simplify_cfg_jump_thread_crash.sil

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

156156
}
157157

158+
// -----------------------------------------------------------------------------
159+
// Test jump-threading through a non-pure address producer.
160+
//
161+
// BB3 cannot (currently) be cloned because the block cloner does not
162+
// know how to sink address producers unless they are pure address
163+
// projections. init_existential_addr is not a pure projection. It's
164+
// address is transitively used outside bb3 via %17 =
165+
// tuple_element_addr. Test that cloning is inhibited. If cloning did
166+
// happen, then it would either need to sink init_existential_addr, or
167+
// SSA would be incorrectly updated.
168+
158169
enum FakeOptional<T> {
159170
case some(T)
160171
case none
@@ -172,9 +183,16 @@ class C {
172183
func f() -> FakeOptional<T>
173184
}
174185

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 {
186+
// Make BB3 is not jump-threaded. And init_existential_addr is not cloned
187+
//
188+
// CHECK-LABEL: sil hidden @nonPureAddressProducer : $@convention(method) (@guaranteed C) -> @out Any {
189+
// CHECK: bb0(%0 : $*Any, %1 : $C):
190+
// CHECK: switch_enum %{{.*}} : $FakeOptional<T>, case #FakeOptional.some!enumelt: bb1, case #FakeOptional.none!enumelt: bb2
191+
// CHECK: bb3(%{{.*}} : $FakeOptional<Int64>):
192+
// CHECK: init_existential_addr %0 : $*Any, $(FakeOptional<Int64>, FakeOptional<S>)
193+
// CHECK: switch_enum %{{.*}} : $FakeOptional<T>, case #FakeOptional.some!enumelt: bb4, case #FakeOptional.none!enumelt: bb6
194+
// CHECK-LABEL: } // end sil function 'nonPureAddressProducer'
195+
sil hidden @nonPureAddressProducer : $@convention(method) (@guaranteed C) -> @out Any {
178196
bb0(%0 : $*Any, %1 : $C):
179197
%3 = class_method %1 : $C, #C.f : (C) -> () -> FakeOptional<T>, $@convention(method) (@guaranteed C) -> FakeOptional<T>
180198
%4 = apply %3(%1) : $@convention(method) (@guaranteed C) -> FakeOptional<T>

0 commit comments

Comments
 (0)