@@ -155,6 +155,17 @@ bb9(%29 : $Optional<AA>):
155
155
156
156
}
157
157
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
+
158
169
enum FakeOptional<T> {
159
170
case some(T)
160
171
case none
@@ -172,9 +183,16 @@ class C {
172
183
func f() -> FakeOptional<T>
173
184
}
174
185
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 {
178
196
bb0(%0 : $*Any, %1 : $C):
179
197
%3 = class_method %1 : $C, #C.f : (C) -> () -> FakeOptional<T>, $@convention(method) (@guaranteed C) -> FakeOptional<T>
180
198
%4 = apply %3(%1) : $@convention(method) (@guaranteed C) -> FakeOptional<T>
0 commit comments