mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Empty access scopes can be a result of e.g. redundant-load-elimination. It's still important to keep those access scopes to detect access violations. Even if the load is physically not done anymore, in case of a conflicting access a propagated load is still wrong and must be detected. rdar://164571252
68 lines
943 B
Swift
68 lines
943 B
Swift
// RUN: %target-run-simple-swift(-Onone)
|
|
// RUN: %target-run-simple-swift(-O)
|
|
|
|
// REQUIRES: executable_test
|
|
|
|
import StdlibUnittest
|
|
|
|
|
|
var tests = TestSuite("exclusivity checking")
|
|
|
|
struct NC: ~Copyable {
|
|
var i: Int = 1
|
|
|
|
mutating func add(_ other: borrowing Self) {
|
|
i += other.i
|
|
i += other.i
|
|
print(self.i, other.i)
|
|
}
|
|
}
|
|
|
|
class C1 {
|
|
var nc = NC()
|
|
|
|
func foo() {
|
|
nc.add(nc)
|
|
}
|
|
}
|
|
|
|
struct S {
|
|
var i: Int = 1
|
|
|
|
mutating func add(_ c: C2) {
|
|
let other = c.getS()
|
|
i += other.i
|
|
i += other.i
|
|
print(self.i, other.i)
|
|
}
|
|
}
|
|
|
|
final class C2 {
|
|
var s = S()
|
|
|
|
@inline(never)
|
|
func getS() -> S { s }
|
|
|
|
func foo() {
|
|
s.add(self)
|
|
}
|
|
}
|
|
|
|
tests.test("non-copyable type")
|
|
.crashOutputMatches("Simultaneous accesses")
|
|
.code {
|
|
expectCrashLater()
|
|
|
|
C1().foo()
|
|
}
|
|
|
|
tests.test("copyable type")
|
|
.crashOutputMatches("Simultaneous accesses")
|
|
.code {
|
|
expectCrashLater()
|
|
|
|
C2().foo()
|
|
}
|
|
|
|
runAllTests()
|