1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
// RUN: %target-swift-emit-sil -enable-experimental-feature NoImplicitCopy -sil-verify-all -verify -enable-library-evolution %s
// This test is used to validate that we properly handle library evolution code
// until we can get all of the normal moveonly_addresschecker_diagnostics test
// case to pass.
////////////////////////
// MARK: Declarations //
////////////////////////
@_moveOnly public struct EmptyStruct {}
@_moveOnly public struct NonEmptyStruct {
var e = EmptyStruct()
}
public class CopyableKlass {
var varS = NonEmptyStruct()
var letS = NonEmptyStruct()
}
public struct CopyableStruct {
var k = CopyableKlass()
}
public func borrowVal(_ x: borrowing NonEmptyStruct) {}
public func borrowVal(_ x: borrowing EmptyStruct) {}
public func borrowVal(_ x: borrowing CopyableKlass) {}
public func borrowVal(_ x: borrowing CopyableStruct) {}
public func consumeVal(_ x: consuming CopyableKlass) {}
public func consumeVal(_ x: consuming NonEmptyStruct) {}
public func consumeVal(_ x: consuming EmptyStruct) {}
let copyableKlassLetGlobal = CopyableKlass()
var copyableKlassVarGlobal = CopyableKlass()
/////////////////
// MARK: Tests //
/////////////////
public struct DeinitTest : ~Copyable {
deinit {}
}
public protocol P {}
public struct GenericDeinitTest<T : P> : ~Copyable {
deinit {}
}
//////////////////////////////////////////
// MARK: Caller Argument Let Spill Test //
//////////////////////////////////////////
public func callerBorrowClassLetFieldForArgumentSpillingTestLet() {
let x = CopyableKlass()
borrowVal(x.letS.e)
}
public func callerBorrowClassLetFieldForArgumentSpillingTestVar() {
var x = CopyableKlass()
x = CopyableKlass()
borrowVal(x.letS.e)
}
public func callerBorrowClassLetFieldForArgumentSpillingTestArg(_ x: CopyableKlass) {
borrowVal(x.letS.e)
}
public func callerBorrowClassLetFieldForArgumentSpillingTestInOutArg(_ x: inout CopyableKlass) {
borrowVal(x.letS.e)
}
public func callerBorrowClassLetFieldForArgumentSpillingTestConsumingArg(_ x: consuming CopyableKlass) {
borrowVal(x.letS.e)
}
public func callerBorrowClassLetFieldForArgumentSpillingTestLetGlobal() {
borrowVal(copyableKlassLetGlobal.letS.e)
}
public func callerBorrowClassLetFieldForArgumentSpillingTestVarGlobal() {
borrowVal(copyableKlassVarGlobal.letS.e)
}
public func callerConsumeClassLetFieldForArgumentSpillingTestLet() {
let x = CopyableKlass()
consumeVal(x.letS.e) // expected-error{{field 'x.letS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
public func callerConsumeClassLetFieldForArgumentSpillingTestVar() {
var x = CopyableKlass()
x = CopyableKlass()
consumeVal(x.letS.e) // expected-error{{field 'x.letS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
public func callerConsumeClassLetFieldForArgumentSpillingTestArg(_ x: CopyableKlass) {
consumeVal(x.letS.e) // expected-error{{field 'x.letS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
public func callerConsumeClassLetFieldForArgumentSpillingTestInOutArg(_ x: inout CopyableKlass) {
consumeVal(x.letS.e) // expected-error{{field 'x.letS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
// TODO: more specific error message path than "unknown"
public func callerConsumeClassLetFieldForArgumentSpillingTestConsumingArg(_ x: consuming CopyableKlass) {
consumeVal(x.letS.e) // expected-error{{field 'x.letS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
public func callerConsumeClassLetFieldForArgumentSpillingTestLetGlobal() {
consumeVal(copyableKlassLetGlobal.letS.e) // expected-error{{field 'copyableKlassLetGlobal.letS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
public func callerConsumeClassLetFieldForArgumentSpillingTestVarGlobal() {
consumeVal(copyableKlassVarGlobal.letS.e) // expected-error{{field 'copyableKlassVarGlobal.letS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
////////////////////
// MARK: Var Test //
////////////////////
public func callerBorrowClassVarFieldForArgumentSpillingTestLet() {
let x = CopyableKlass()
borrowVal(x.varS.e)
}
public func callerBorrowClassVarFieldForArgumentSpillingTestVar() {
var x = CopyableKlass()
x = CopyableKlass()
borrowVal(x.varS.e)
}
public func callerBorrowClassVarFieldForArgumentSpillingTestArg(_ x: CopyableKlass) {
borrowVal(x.varS.e)
}
public func callerBorrowClassVarFieldForArgumentSpillingTestInOutArg(_ x: inout CopyableKlass) {
borrowVal(x.varS.e)
}
public func callerBorrowClassVarFieldForArgumentSpillingTestConsumingArg(_ x: consuming CopyableKlass) {
borrowVal(x.varS.e)
}
public func callerBorrowClassVarFieldForArgumentSpillingTestLetGlobal() {
borrowVal(copyableKlassLetGlobal.varS.e)
}
public func callerBorrowClassVarFieldForArgumentSpillingTestVarGlobal() {
borrowVal(copyableKlassVarGlobal.varS.e)
}
public func callerConsumeClassVarFieldForArgumentSpillingTestLet() {
let x = CopyableKlass()
consumeVal(x.varS.e) // expected-error{{field 'x.varS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
public func callerConsumeClassVarFieldForArgumentSpillingTestVar() {
var x = CopyableKlass()
x = CopyableKlass()
consumeVal(x.varS.e) // expected-error{{field 'x.varS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
public func callerConsumeClassVarFieldForArgumentSpillingTestArg(_ x: CopyableKlass) {
consumeVal(x.varS.e) // expected-error{{field 'x.varS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
public func callerConsumeClassVarFieldForArgumentSpillingTestInOutArg(_ x: inout CopyableKlass) {
consumeVal(x.varS.e) // expected-error{{field 'x.varS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
// TODO: more precise error path reporting than 'unknown'
public func callerConsumeClassVarFieldForArgumentSpillingTestConsumingArg(_ x: consuming CopyableKlass) {
consumeVal(x.varS.e) // expected-error{{field 'x.varS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
public func callerConsumeClassVarFieldForArgumentSpillingTestLetGlobal() {
consumeVal(copyableKlassLetGlobal.varS.e) // expected-error{{field 'copyableKlassLetGlobal.varS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
public func callerConsumeClassVarFieldForArgumentSpillingTestVarGlobal() {
consumeVal(copyableKlassVarGlobal.varS.e) // expected-error{{field 'copyableKlassVarGlobal.varS' was consumed but not reinitialized; the field must be reinitialized during the access}}
// expected-note@-1{{consumed here}}
}
|