|
| 1 | +// RUN: %target-sil-opt -enable-sil-verify-all -closure-lifetime-fixup -emit-verbose-sil %s | %FileCheck %s |
| 2 | + |
| 3 | +import Builtin |
| 4 | +import Swift |
| 5 | +import SwiftShims |
| 6 | + |
| 7 | + |
| 8 | +sil_scope 1 { loc "closure-lifetime-fixup-debuginfo.sil":12:34 parent @destroy_and_dealloc_of_capture_are_cleanups : $@convention(method) <Self where Self : Indexable> (@in Self) -> () } |
| 9 | +sil_scope 2 { loc "closure-lifetime-fixup-debuginfo.sil":12:34 parent 1 } |
| 10 | + |
| 11 | +protocol Indexable { |
| 12 | +associatedtype Index |
| 13 | +} |
| 14 | + |
| 15 | +// Verify that the destroy_addr and dealloc_stack that are created for captured |
| 16 | +// closure arguments are marked as cleanups. |
| 17 | +// CHECK-LABEL: sil [ossa] @destroy_and_dealloc_of_capture_are_cleanups : {{.*}} { |
| 18 | +// CHECK: [[CAPTURED_ADDR:%[^,]+]] = alloc_stack $Self |
| 19 | +// CHECK: try_apply {{.*}}, normal [[SUCCESS:bb[0-9]+]] |
| 20 | +// CHECK: [[SUCCESS]] |
| 21 | +// CHECK: destroy_addr [[CAPTURED_ADDR]]{{.*}} // id: {{%[^,]+}}; <invalid loc>:cleanup:auto_gen |
| 22 | +// ^^^^^^^ |
| 23 | +// CHECK: dealloc_stack [[CAPTURED_ADDR]]{{.*}} // id: {{%[^,]+}}; <invalid loc>:cleanup:auto_gen |
| 24 | +// ^^^^^^^ |
| 25 | +// CHECK-LABEL: } // end sil function 'destroy_and_dealloc_of_capture_are_cleanups' |
| 26 | +sil [ossa] @destroy_and_dealloc_of_capture_are_cleanups : $@convention(method) <Self where Self : Indexable> (@in Self) -> () { |
| 27 | +bb0(%self : $*Self): |
| 28 | + %copy = alloc_stack $Self, scope 1 |
| 29 | + copy_addr %self to [init] %copy : $*Self, scope 2 |
| 30 | + %closure = partial_apply [callee_guaranteed] undef<Self>(%copy) : $@convention(thin) <Tee where Tee : Indexable> (@in_guaranteed Tee) -> (@out Tee.Index, @error any Error), scope 2 |
| 31 | + %converted = convert_function %closure : $@callee_guaranteed () -> (@out Self.Index, @error any Error) to $@callee_guaranteed @substituted <Tee> () -> (@out Tee, @error any Error) for <Self.Index>, scope 2 |
| 32 | + %noescape = convert_escape_to_noescape [not_guaranteed] %converted : $@callee_guaranteed @substituted <Tee> () -> (@out Tee, @error any Error) for <Self.Index> to $@noescape @callee_guaranteed @substituted <Tee> () -> (@out Tee, @error any Error) for <Self.Index>, scope 2 |
| 33 | + try_apply undef<Self.Index>(%noescape) : $@convention(thin) <Tee> (@noescape @callee_guaranteed @substituted <Tee> () -> (@out Tee, @error any Error) for <Tee>) -> (@error any Error), normal bb1, error bb2, scope 2 |
| 34 | +bb1(%result : $()): |
| 35 | + destroy_value %converted : $@callee_guaranteed @substituted <Tee> () -> (@out Tee, @error any Error) for <Self.Index>, scope 2 |
| 36 | + destroy_addr %self : $*Self, scope 2 |
| 37 | + %retval = tuple (), scope 2 |
| 38 | + dealloc_stack %copy : $*Self, scope 2 |
| 39 | + return %retval : $(), scope 2 |
| 40 | + |
| 41 | +bb2(%83 : @owned $any Error): |
| 42 | + unreachable , scope 2 |
| 43 | +} |
0 commit comments