Skip to content

Commit dbd0b20

Browse files
committed
[move-function] Add more var tests around reinit diagnostics.
1 parent 5aa34f4 commit dbd0b20

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

test/SILOptimizer/move_function_kills_copyable_loadable_vars.swift

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class Klass {}
1212

1313
func consumingUse(_ k: __owned Klass) {}
1414
var booleanValue: Bool { false }
15+
var booleanValue2: Bool { false }
1516
func nonConsumingUse(_ k: Klass) {}
1617

1718
///////////
@@ -94,6 +95,57 @@ public func performMoveOnVarMultiBlockError2(_ p: Klass) {
9495
nonConsumingUse(x)
9596
}
9697

98+
public func performMoveConditionalReinitalization(_ p: Klass) {
99+
var x = p
100+
101+
if booleanValue {
102+
nonConsumingUse(x)
103+
let _ = _move(x)
104+
x = p
105+
nonConsumingUse(x)
106+
} else {
107+
nonConsumingUse(x)
108+
}
109+
110+
nonConsumingUse(x)
111+
}
112+
113+
public func performMoveConditionalReinitalization2(_ p: Klass) {
114+
var x = p // expected-error {{'x' used after being moved}}
115+
116+
if booleanValue {
117+
nonConsumingUse(x)
118+
let _ = _move(x) // expected-note {{move here}}
119+
nonConsumingUse(x) // expected-note {{use here}}
120+
x = p
121+
nonConsumingUse(x)
122+
} else {
123+
nonConsumingUse(x)
124+
}
125+
126+
nonConsumingUse(x)
127+
}
128+
129+
public func performMoveConditionalReinitalization3(_ p: Klass, _ p2: Klass, _ p3: Klass) {
130+
var x = p // expected-error {{'x' used after being moved}}
131+
// expected-error @-1 {{'x' used after being moved}}
132+
133+
if booleanValue {
134+
nonConsumingUse(x)
135+
let _ = _move(x) // expected-note {{move here}}
136+
nonConsumingUse(x) // expected-note {{use here}}
137+
nonConsumingUse(x) // We only emit for the first one.
138+
x = p2
139+
nonConsumingUse(x)
140+
let _ = _move(x) // expected-note {{move here}}
141+
nonConsumingUse(x) // expected-note {{use here}}
142+
} else {
143+
nonConsumingUse(x)
144+
}
145+
146+
nonConsumingUse(x)
147+
}
148+
97149
// Even though the examples below are for lets, since the let is not initially
98150
// defined it comes out like a var.
99151
public func performMoveOnLaterDefinedInit(_ p: Klass) {

0 commit comments

Comments
 (0)