File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
SwiftCompilerSources/Sources/Optimizer/InstructionSimplification Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -257,11 +257,15 @@ private extension AllocStackInst {
257
257
case is CheckedCastAddrBranchInst , is UnconditionalCheckedCastAddrInst :
258
258
// To construct a new cast instruction we need a formal type.
259
259
requiresLegalFormalType = true
260
- fallthrough
261
- case is UncheckedAddrCastInst :
262
260
if use != use. instruction. operands [ 0 ] {
263
261
return nil
264
262
}
263
+ case is UncheckedAddrCastInst :
264
+ if self . type. isExistential {
265
+ // Bail if the address of the original existential escapes.
266
+ // This is not a problem if the alloc_stack already contains the opened existential.
267
+ return nil
268
+ }
265
269
default :
266
270
return nil
267
271
}
Original file line number Diff line number Diff line change @@ -365,3 +365,19 @@ bb0(%0 : @owned $C2):
365
365
dealloc_stack %1
366
366
return %5
367
367
}
368
+
369
+ // CHECK-LABEL: sil [ossa] @dont_replace_existential_with_escaping_addr :
370
+ // CHECK: alloc_stack $any P
371
+ // CHECK: } // end sil function 'dont_replace_existential_with_escaping_addr'
372
+ sil [ossa] @dont_replace_existential_with_escaping_addr : $@convention(thin) <V> (@thick V.Type, @owned C2) -> @out V {
373
+ bb0(%0 : $*V, %1 : $@thick V.Type, %2 : @owned $C2):
374
+ %114 = alloc_stack $any P
375
+ %117 = init_existential_addr %114, $C2
376
+ store %2 to [init] %117
377
+ %129 = unchecked_addr_cast %114 to $*V
378
+ copy_addr %129 to [init] %0
379
+ destroy_addr %114
380
+ dealloc_stack %114
381
+ %137 = tuple ()
382
+ return %137
383
+ }
You can’t perform that action at this time.
0 commit comments