Skip to content

Commit f8d0c69

Browse files
committed
[move-only] Clone all __owned tests into consuming tests.
I left in the __owned tests of course. rdar://108511703
1 parent a25080c commit f8d0c69

File tree

3 files changed

+1364
-16
lines changed

3 files changed

+1364
-16
lines changed

test/SILOptimizer/moveonly_addresschecker_diagnostics.swift

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,12 @@ public func finalClassSimpleNonConsumingUseTest(_ x: __owned FinalKlass) {
459459
borrowVal(x2)
460460
}
461461

462+
public func finalClassSimpleNonConsumingUseTest2(_ x: consuming FinalKlass) {
463+
var x2 = x
464+
x2 = FinalKlass()
465+
borrowVal(x2)
466+
}
467+
462468
public func finalClassSimpleNonConsumingUseTestArg(_ x2: inout FinalKlass) {
463469
borrowVal(x2)
464470
}
@@ -2142,6 +2148,24 @@ func moveOperatorTest(_ k: __owned Klass) {
21422148
let _ = k3
21432149
}
21442150

2151+
func moveOperatorTest2(_ k: consuming Klass) {
2152+
var k2 = k
2153+
// expected-error @-1 {{'k2' consumed more than once}}
2154+
// expected-error @-2 {{'k2' consumed more than once}}
2155+
// expected-error @-3 {{'k2' consumed more than once}}
2156+
k2 = Klass()
2157+
let k3 = consume k2 // expected-note {{consuming use here}}
2158+
let _ = consume k2
2159+
// expected-note @-1 {{consuming use here}}
2160+
// expected-note @-2 {{consuming use here}}
2161+
_ = k2
2162+
// expected-note @-1 {{consuming use here}}
2163+
// expected-note @-2 {{consuming use here}}
2164+
let _ = k2
2165+
// expected-note @-1 {{consuming use here}}
2166+
let _ = k3
2167+
}
2168+
21452169
/////////////////////////////////////////
21462170
// Black hole initialization test case//
21472171
/////////////////////////////////////////
@@ -2170,6 +2194,30 @@ func blackHoleKlassTestCase(_ k: __owned Klass) {
21702194
// expected-note @-1 {{consuming use here}}
21712195
}
21722196

2197+
func blackHoleKlassTestCase2(_ k: consuming Klass) {
2198+
var k2 = k
2199+
// expected-error @-1 {{'k2' consumed more than once}}
2200+
// expected-error @-2 {{'k2' consumed more than once}}
2201+
// expected-error @-3 {{'k2' consumed more than once}}
2202+
// expected-error @-4 {{'k2' consumed more than once}}
2203+
let _ = k2 // expected-note {{consuming use here}}
2204+
let _ = k2 // expected-note {{consuming use here}}
2205+
2206+
k2 = Klass()
2207+
var _ = k2 // expected-note {{consuming use here}}
2208+
var _ = k2
2209+
// expected-note @-1 {{consuming use here}}
2210+
// expected-note @-2 {{consuming use here}}
2211+
2212+
_ = k2
2213+
// expected-note @-1 {{consuming use here}}
2214+
// expected-note @-2 {{consuming use here}}
2215+
2216+
// TODO: Why do we not also get 2 errors here?
2217+
_ = k2
2218+
// expected-note @-1 {{consuming use here}}
2219+
}
2220+
21732221
///////////////////////////////////////
21742222
// Copyable Type in a Move Only Type //
21752223
///////////////////////////////////////
@@ -2451,6 +2499,14 @@ func borrowAndConsumeAtSameTimeTest(x: __owned NonTrivialStruct) { // expected-e
24512499
// expected-note @-2 {{non-consuming use here}}
24522500
}
24532501

2502+
func borrowAndConsumeAtSameTimeTest2(x: consuming NonTrivialStruct) { // expected-error {{'x' used after consume}}
2503+
borrowAndConsumeAtSameTime(x, consume: x)
2504+
// expected-note @-1 {{consuming use here}}
2505+
// expected-note @-2 {{non-consuming use here}}
2506+
// expected-error @-3 {{overlapping accesses to 'x', but deinitialization requires exclusive access; consider copying to a local variable}}
2507+
// expected-note @-4 {{conflicting access is here}}
2508+
}
2509+
24542510
////////////////
24552511
// Yield Test //
24562512
////////////////

0 commit comments

Comments
 (0)