@@ -155,3 +155,60 @@ bb9(%29 : $Optional<AA>):
155
155
156
156
}
157
157
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