@@ -8,6 +8,7 @@ struct E<T>: ~Copyable {
8
8
var t : T
9
9
}
10
10
11
+ class Klass { }
11
12
struct C < T> {
12
13
var t : T
13
14
}
@@ -19,13 +20,31 @@ func escaping(_ x: @escaping () -> ()) { escaper = x }
19
20
20
21
func borrow< T> ( _: borrowing E < T > ) { }
21
22
func borrow< T> ( _: borrowing C < T > ) { }
23
+ func mutate< T> ( _: inout C < T > ) { }
24
+
25
+ // CHECK-LABEL: sil {{.*}}14testCopySafetyyyAA1CVyxGlF :
26
+ // CHECK: [[STK1:%.*]] = alloc_stack {{.*}} $C<T>
27
+ // CHECK: copy_addr %0 to [init] [[STK1]]
28
+ // CHECK: partial_apply {{.*}}[on_stack] {{.*}}([[STK1]]) : $@convention(thin) <τ_0_0> (@inout_aliasable C<τ_0_0>) -> ()
29
+ // CHECK: [[STK2:%.*]] = alloc_stack {{.*}} $C<T>
30
+ // CHECK: [[BA:%.*]] = begin_access [read] [static] [[STK1]]
31
+ // CHECK: copy_addr [[BA]] to [init] [[STK2]]
32
+ // CHECK: end_access [[BA]]
33
+ // CHECK: partial_apply {{.*}}[on_stack] {{.*}}([[STK2]]) : $@convention(thin) <τ_0_0> (@in_guaranteed C<τ_0_0>) -> ()
34
+ func testCopySafety< T> ( _ c: C < T > ) {
35
+ var mutC = c
36
+ nonescaping ( { mutate ( & mutC) } , and: { [ mutC] in borrow ( mutC) } )
37
+ }
22
38
23
- func testMultiCapture< T> ( _ e: borrowing E < T > , _ c: C < T > ) {
24
- // CHECK: partial_apply {{.*}}[on_stack] {{.*}}(%1, %0) :
25
- nonescaping {
26
- borrow ( c)
27
- borrow ( e)
28
- }
39
+ // CHECK-LABEL: sil {{.*}}18testVarReadCaptureyyAA1CVyxGlF :
40
+ // CHECK: [[STK:%.*]] = alloc_stack {{.*}} $C<T>
41
+ // CHECK: copy_addr %0 to [init] [[STK]]
42
+ // CHECK: partial_apply {{.*}}[on_stack] {{.*}}([[STK]]) : $@convention(thin) <τ_0_0> (@inout_aliasable C<τ_0_0>) -> ()
43
+ func testVarReadCapture< T> ( _ c: C < T > ) {
44
+ var mutC = c
45
+ nonescaping {
46
+ borrow ( mutC)
47
+ }
29
48
}
30
49
31
50
// CHECK-LABEL: sil {{.*}}16testNeverEscaped
0 commit comments