Skip to content

Commit 6fef369

Browse files
committed
Add variants of ~Copyable types to show a ~Copyable struct has OwnershipKind::None
1 parent ab3265d commit 6fef369

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed

test/SIL/moveonly_ownership.sil

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// RUN: %target-sil-opt -test-runner %s -o /dev/null 2>&1 | %FileCheck %s
2+
3+
sil_stage raw
4+
5+
import Builtin
6+
import Swift
7+
import SwiftShims
8+
9+
@_moveOnly struct MO_DEINIT {
10+
@_hasStorage var value: Int { get set }
11+
deinit
12+
init(value: Int)
13+
}
14+
15+
struct NC_DEINIT : ~Copyable {
16+
@_hasStorage var value: Int { get set }
17+
deinit
18+
init(value: Int)
19+
}
20+
21+
@_moveOnly struct MO {
22+
@_hasStorage var value: Int { get set }
23+
}
24+
25+
struct NC : ~Copyable {
26+
@_hasStorage var value: Int { get set }
27+
}
28+
29+
// CHECK: begin running test 1 of 4 on motest1: is-sil-trivial with: @instruction[2]
30+
// CHECK: %2 = struct $MO_DEINIT (%1 : $Int)
31+
// CHECK: is not trivial
32+
// CHECK: end running test 1 of 4 on motest1: is-sil-trivial with: @instruction[2]
33+
// CHECK: begin running test 2 of 4 on motest1: get-ownership-kind with: @instruction[2]
34+
// CHECK: %2 = struct $MO_DEINIT (%1 : $Int)
35+
// CHECK: OwnershipKind: none
36+
// CHECK: end running test 2 of 4 on motest1: get-ownership-kind with: @instruction[2]
37+
// CHECK: begin running test 3 of 4 on motest1: is-sil-trivial with: @instruction[4]
38+
// CHECK: %4 = move_value [lexical] %2 : $MO_DEINIT
39+
// CHECK: is not trivial
40+
// CHECK: end running test 3 of 4 on motest1: is-sil-trivial with: @instruction[4]
41+
// CHECK: begin running test 4 of 4 on motest1: get-ownership-kind with: @instruction[4]
42+
// CHECK: %4 = move_value [lexical] %2 : $MO_DEINIT
43+
// CHECK: OwnershipKind: owned
44+
// CHECK: end running test 4 of 4 on motest1: get-ownership-kind with: @instruction[4]
45+
sil hidden [ossa] @motest1 : $@convention(thin) () -> () {
46+
[global: read,write,copy,destroy,allocate,deinit_barrier]
47+
bb0:
48+
specify_test "is-sil-trivial @instruction[2]"
49+
specify_test "get-ownership-kind @instruction[2]"
50+
specify_test "is-sil-trivial @instruction[4]"
51+
specify_test "get-ownership-kind @instruction[4]"
52+
%0 = integer_literal $Builtin.Int64, 38
53+
%1 = struct $Int (%0 : $Builtin.Int64)
54+
%2 = struct $MO_DEINIT (%1 : $Int)
55+
debug_value %2 : $MO_DEINIT, let, name "b"
56+
%4 = move_value [lexical] %2 : $MO_DEINIT
57+
destroy_value %4 : $MO_DEINIT
58+
%6 = tuple ()
59+
return %6 : $()
60+
}
61+
62+
// CHECK: begin running test 1 of 4 on motest2: is-sil-trivial with: @instruction[2]
63+
// CHECK: %2 = struct $MO (%1 : $Int)
64+
// CHECK: is not trivial
65+
// CHECK: end running test 1 of 4 on motest2: is-sil-trivial with: @instruction[2]
66+
// CHECK: begin running test 2 of 4 on motest2: get-ownership-kind with: @instruction[2]
67+
// CHECK: %2 = struct $MO (%1 : $Int)
68+
// CHECK: OwnershipKind: none
69+
// CHECK: end running test 2 of 4 on motest2: get-ownership-kind with: @instruction[2]
70+
// CHECK: begin running test 3 of 4 on motest2: is-sil-trivial with: @instruction[4]
71+
// CHECK: %4 = move_value [lexical] %2 : $MO
72+
// CHECK: is not trivial
73+
// CHECK: end running test 3 of 4 on motest2: is-sil-trivial with: @instruction[4]
74+
// CHECK: begin running test 4 of 4 on motest2: get-ownership-kind with: @instruction[4]
75+
// CHECK: %4 = move_value [lexical] %2 : $MO
76+
// CHECK: OwnershipKind: owned
77+
// CHECK: end running test 4 of 4 on motest2: get-ownership-kind with: @instruction[4]
78+
sil hidden [ossa] @motest2 : $@convention(thin) () -> () {
79+
[global: read,write,copy,destroy,allocate,deinit_barrier]
80+
bb0:
81+
specify_test "is-sil-trivial @instruction[2]"
82+
specify_test "get-ownership-kind @instruction[2]"
83+
specify_test "is-sil-trivial @instruction[4]"
84+
specify_test "get-ownership-kind @instruction[4]"
85+
%0 = integer_literal $Builtin.Int64, 38
86+
%1 = struct $Int (%0 : $Builtin.Int64)
87+
%2 = struct $MO (%1 : $Int)
88+
debug_value %2 : $MO, let, name "b"
89+
%4 = move_value [lexical] %2 : $MO
90+
destroy_value %4 : $MO
91+
%6 = tuple ()
92+
return %6 : $()
93+
}
94+
95+
// CHECK: begin running test 1 of 4 on nctest1: is-sil-trivial with: @instruction[2]
96+
// CHECK: %2 = struct $NC_DEINIT (%1 : $Int)
97+
// CHECK: is not trivial
98+
// CHECK: end running test 1 of 4 on nctest1: is-sil-trivial with: @instruction[2]
99+
// CHECK: begin running test 2 of 4 on nctest1: get-ownership-kind with: @instruction[2]
100+
// CHECK: %2 = struct $NC_DEINIT (%1 : $Int)
101+
// CHECK: OwnershipKind: none
102+
// CHECK: end running test 2 of 4 on nctest1: get-ownership-kind with: @instruction[2]
103+
// CHECK: begin running test 3 of 4 on nctest1: is-sil-trivial with: @instruction[4]
104+
// CHECK: %4 = move_value [lexical] %2 : $NC_DEINIT
105+
// CHECK: is not trivial
106+
// CHECK: end running test 3 of 4 on nctest1: is-sil-trivial with: @instruction[4]
107+
// CHECK: begin running test 4 of 4 on nctest1: get-ownership-kind with: @instruction[4]
108+
// CHECK: %4 = move_value [lexical] %2 : $NC_DEINIT
109+
// CHECK: OwnershipKind: owned
110+
// CHECK: end running test 4 of 4 on nctest1: get-ownership-kind with: @instruction[4]
111+
112+
sil hidden [ossa] @nctest1 : $@convention(thin) () -> () {
113+
[global: read,write,copy,destroy,allocate,deinit_barrier]
114+
bb0:
115+
specify_test "is-sil-trivial @instruction[2]"
116+
specify_test "get-ownership-kind @instruction[2]"
117+
specify_test "is-sil-trivial @instruction[4]"
118+
specify_test "get-ownership-kind @instruction[4]"
119+
%0 = integer_literal $Builtin.Int64, 38
120+
%1 = struct $Int (%0 : $Builtin.Int64)
121+
%2 = struct $NC_DEINIT (%1 : $Int)
122+
debug_value %2 : $NC_DEINIT, let, name "b"
123+
%4 = move_value [lexical] %2 : $NC_DEINIT
124+
destroy_value %4 : $NC_DEINIT
125+
%6 = tuple ()
126+
return %6 : $()
127+
}
128+
129+
// CHECK: begin running test 1 of 4 on nctest2: is-sil-trivial with: @instruction[2]
130+
// CHECK: %2 = struct $NC (%1 : $Int)
131+
// CHECK: is not trivial
132+
// CHECK: end running test 1 of 4 on nctest2: is-sil-trivial with: @instruction[2]
133+
// CHECK: begin running test 2 of 4 on nctest2: get-ownership-kind with: @instruction[2]
134+
// CHECK: %2 = struct $NC (%1 : $Int)
135+
// CHECK: OwnershipKind: none
136+
// CHECK: end running test 2 of 4 on nctest2: get-ownership-kind with: @instruction[2]
137+
// CHECK: begin running test 3 of 4 on nctest2: is-sil-trivial with: @instruction[4]
138+
// CHECK: %4 = move_value [lexical] %2 : $NC
139+
// CHECK: is not trivial
140+
// CHECK: end running test 3 of 4 on nctest2: is-sil-trivial with: @instruction[4]
141+
// CHECK: begin running test 4 of 4 on nctest2: get-ownership-kind with: @instruction[4]
142+
// CHECK: %4 = move_value [lexical] %2 : $NC
143+
// CHECK: OwnershipKind: owned
144+
// CHECK: end running test 4 of 4 on nctest2: get-ownership-kind with: @instruction[4]
145+
sil hidden [ossa] @nctest2 : $@convention(thin) () -> () {
146+
[global: read,write,copy,destroy,allocate,deinit_barrier]
147+
bb0:
148+
specify_test "is-sil-trivial @instruction[2]"
149+
specify_test "get-ownership-kind @instruction[2]"
150+
specify_test "is-sil-trivial @instruction[4]"
151+
specify_test "get-ownership-kind @instruction[4]"
152+
%0 = integer_literal $Builtin.Int64, 38
153+
%1 = struct $Int (%0 : $Builtin.Int64)
154+
%2 = struct $NC (%1 : $Int)
155+
debug_value %2 : $NC, let, name "b"
156+
%4 = move_value [lexical] %2 : $NC
157+
destroy_value %4 : $NC
158+
%6 = tuple ()
159+
return %6 : $()
160+
}
161+

0 commit comments

Comments
 (0)