Files
swift-mirror/test/Interpreter/enforce_exclusive_access_backtrace.swift
Andrew Trick dda3d7be36 [exclusivity] Make KeyPath enforcement an error in Swift 3 mode.
Modify IRGen to emit builtin access markers with an error flag in
Swift 3 mode.

KeyPath enforcement is required by user code in Swift 4+ mode, but is
implemented within the standard library. A [builtin] flag marks the
special case for access generated by Builtins so that they are
always enforced as an error regardless of the language mode.

This is necessary for Swift 4.2 because the standard library continues
to build in Swift 3 mode. Once the standard library build migrates,
this is all irrelevant.

This does not actually affect existing Swift 3 code, since the KeyPath
feature wasn't introduced until Swift 4.

<rdar://problem/40115738> [Exclusivity] Enforce Keypath access as an error, not a warning in 4.2.
2018-05-09 22:52:42 -07:00

47 lines
1.3 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-build-swift -swift-version 3 %s -o %t/a.out -enforce-exclusivity=checked -Onone
//
// RUN: %target-run %t/a.out 2>&1 | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: OS=macosx
import StdlibUnittest
import SwiftPrivatePthreadExtras
import Foundation
struct X {
var i = 7
}
func readAndPerform<T>(_ _: UnsafePointer<T>, closure: () ->()) {
closure()
}
func writeAndPerform<T>(_ _: UnsafeMutablePointer<T>, closure: () ->()) {
closure()
}
var globalX = X()
withUnsafePointer(to: &globalX) { _ = fputs(String(format: "globalX: 0x%lx\n", Int(bitPattern: $0)), stderr) }
// CHECK: globalX: [[ADDR:0x.*]]
fputs("Global Access\n", stderr);
readAndPerform(&globalX) {
globalX = X()
// CHECK-LABEL: Global Access
// CHECK: Simultaneous accesses to [[ADDR]], but modification requires exclusive access.
// CHECK: Previous access (a read) started at a.out`main + {{.*}} (0x{{.*}}).
// CHECK: Current access (a modification) started at:
// CHECK: a.out {{.*}} closure
// CHECK: a.out {{.*}} readAndPerform
// CHECK: a.out {{.*}} main
}
class C {
final var f = 7
}
var c = C()
withUnsafePointer(to: &c.f) { _ = fputs(String(format: "c.f: 0x%lx\n", Int(bitPattern: $0)), stderr) }
// CHECK: c.f: [[C_F_ADDR:0x.*]]