Files
swift-mirror/test/SILOptimizer/exclusivity_violation.swift
Erik Eckstein dbc50633b9 DeadCodeElimination: don't remove empty access scopes
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
2025-11-24 14:49:45 +01:00

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()