Skip to content

Commit bd396bf

Browse files
committed
Add tests to check we won't eliminate copies when they are needed to avoid exclusivity issues
1 parent 83280b3 commit bd396bf

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

test/SILOptimizer/moveonly_closure_lifetime_fixup_address_only_borrowed_captures.swift

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct E<T>: ~Copyable {
88
var t: T
99
}
1010

11+
class Klass {}
1112
struct C<T> {
1213
var t: T
1314
}
@@ -19,13 +20,31 @@ func escaping(_ x: @escaping () -> ()) { escaper = x }
1920

2021
func borrow<T>(_: borrowing E<T>) {}
2122
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+
}
2238

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+
let mutC = c
45+
nonescaping {
46+
borrow(mutC)
47+
}
2948
}
3049

3150
// CHECK-LABEL: sil {{.*}}16testNeverEscaped

0 commit comments

Comments
 (0)