1
+ // RUN: %target-sil-opt -transfer-non-sendable -enable-sil-opaque-values -enable-experimental-feature RegionBasedIsolation -strict-concurrency=complete %s -verify
2
+
3
+ // PLEASE READ THIS!
4
+ //
5
+ // This test is specifically to test out individual instruction interactions,
6
+ // not for crashers. The idea is to make it so that we have one test for every
7
+ // SIL instruction, so please add a test here when you add a new instruction.
8
+ //
9
+ // For assign/lookthrough, just add a test that triggers an ownership error. If it is
10
+ // a more complex instruction, talk with @gottesmm.
11
+
12
+ sil_stage raw
13
+
14
+ import Swift
15
+ import Builtin
16
+
17
+ class NonSendableKlass {}
18
+
19
+ final class SendableKlass : Sendable {}
20
+
21
+ @_moveOnly
22
+ struct NonSendableMoveOnlyStruct {
23
+ var ns: NonSendableKlass
24
+ }
25
+
26
+ struct NonSendableStruct {
27
+ var ns: NonSendableKlass
28
+ }
29
+
30
+ sil @transferRawPointer : $@convention(thin) @async (Builtin.RawPointer) -> ()
31
+ sil @useRawPointer : $@convention(thin) (Builtin.RawPointer) -> ()
32
+
33
+ sil @transferSendableKlass : $@convention(thin) @async (@guaranteed SendableKlass) -> ()
34
+ sil @constructSendableKlass : $@convention(thin) () -> @owned SendableKlass
35
+
36
+ sil @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
37
+ sil @useNonSendableKlass : $@convention(thin) (@guaranteed NonSendableKlass) -> ()
38
+ sil @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
39
+
40
+ sil @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
41
+ sil @useIndirect : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
42
+
43
+ sil @constructMoveOnlyStruct : $@convention(thin) () -> @owned NonSendableMoveOnlyStruct
44
+
45
+ enum FakeOptional<T> {
46
+ case none
47
+ case some(T)
48
+ }
49
+
50
+ /////////////////
51
+ // MARK: Tests //
52
+ /////////////////
53
+
54
+ sil [ossa] @test_unowned_copy_value : $@convention(thin) @async <T where T : AnyObject> (@owned T) -> () {
55
+ bb0(%owned_value : @owned $T):
56
+ %unowned_value = unowned_copy_value %owned_value : $T
57
+
58
+ %4 = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
59
+ apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %4<@sil_unowned T>(%unowned_value) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
60
+
61
+ destroy_value %unowned_value : $@sil_unowned T
62
+ //destroy_value %value : $T
63
+ destroy_value %owned_value : $T
64
+
65
+ %9999 = tuple ()
66
+ return %9999 : $()
67
+ }
0 commit comments