mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
91257bb488
In release builds that enable dynamic exclusivity checking, we are including all of the printing code for producing the nice "simultaneous access" failure message. That increases code size too much, so only include this in debug builds. For release builds, we just trap here. Fixes rdar://173338152.
68 lines
1.6 KiB
Swift
68 lines
1.6 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library %s -c -o %t/a.o -enforce-exclusivity=checked -enable-experimental-feature EmbeddedDynamicExclusivity
|
|
|
|
// Multi-threaded exclusivity checking implementation (that uses C11 thread_local).
|
|
// RUN: %target-clang %t/a.o %target-embedded-posix-shim -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%module-target-triple %target-clang-resource-dir-opt -lswift_Concurrency %target-swift-default-executor-opt -dead_strip -lswiftExclusivityC11ThreadLocal
|
|
// RUN: %target-run not --crash %t/a.out
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: swift_in_compiler
|
|
// REQUIRES: optimized_stdlib
|
|
// REQUIRES: swift_feature_Embedded
|
|
// REQUIRES: swift_feature_EmbeddedDynamicExclusivity
|
|
|
|
// UNSUPPORTED: OS=wasip1
|
|
|
|
struct NC: ~Copyable {
|
|
var i: Int = 1
|
|
|
|
mutating func add(_ other: borrowing Self) {
|
|
i += other.i
|
|
i += other.i
|
|
print(self.i)
|
|
print(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)
|
|
print(other.i)
|
|
}
|
|
}
|
|
|
|
final class C2 {
|
|
var s = S()
|
|
|
|
@inline(never)
|
|
func getS() -> S { s }
|
|
|
|
func foo() {
|
|
s.add(self)
|
|
}
|
|
}
|
|
|
|
@main
|
|
struct Main {
|
|
static func main() {
|
|
// Note: not actually checked because it doesn't get flushed.
|
|
// CHECK: Simultaneous access to 0x{{.*}}, but modification requires exclusive access
|
|
// CHECK: Previous access (a modify) started at 0x{{.*}}
|
|
// CHECK: Current access (a read) started at 0x{{.*}}
|
|
C1().foo()
|
|
}
|
|
}
|