Skip to content

Commit d62a018

Browse files
authored
Merge pull request swiftlang#20442 from atrick/Ounchecked-exclusivity
Disable runtime exclusivity checks with -Ounchecked.
2 parents 4fb4cb0 + f836e76 commit d62a018

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,11 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
774774
Opts.VerifyExclusivity
775775
= A->getOption().matches(OPT_enable_verify_exclusivity);
776776
}
777+
// If runtime asserts are disabled in general, also disable runtime
778+
// exclusivity checks unless explicitly requested.
779+
if (Opts.RemoveRuntimeAsserts)
780+
Opts.EnforceExclusivityDynamic = false;
781+
777782
if (const Arg *A = Args.getLastArg(options::OPT_enforce_exclusivity_EQ)) {
778783
parseExclusivityEnforcementOptions(A, Opts, Diags);
779784
}

test/SILOptimizer/access_enforcement_noescape.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %target-swift-frontend -module-name access_enforcement_noescape -enable-sil-ownership -enforce-exclusivity=checked -Onone -emit-sil -swift-version 4 -parse-as-library %s | %FileCheck %s
2-
// REQUIRES: asserts
32

43
// This tests SILGen and AccessEnforcementSelection as a single set of tests.
54
// (Some static/dynamic enforcement selection is done in SILGen, and some is
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %target-swift-frontend -enable-sil-ownership -Onone -emit-sil -parse-as-library %s | %FileCheck %s --check-prefix=CHECK --check-prefix=NONE
2+
// RUN: %target-swift-frontend -enable-sil-ownership -Osize -emit-sil -parse-as-library %s | %FileCheck %s --check-prefix=CHECK --check-prefix=OPT
3+
// RUN: %target-swift-frontend -enable-sil-ownership -O -emit-sil -parse-as-library %s | %FileCheck %s --check-prefix=CHECK --check-prefix=OPT
4+
// RUN: %target-swift-frontend -enable-sil-ownership -Ounchecked -emit-sil -parse-as-library %s | %FileCheck %s --check-prefix=CHECK --check-prefix=UNCHECKED
5+
6+
@inline(never)
7+
func takesInoutAndEscaping(_: inout Int, _ f: @escaping () -> ()) {
8+
f()
9+
}
10+
11+
@inline(never)
12+
func escapeClosure(_ f: @escaping () -> ()) -> () -> () {
13+
return f
14+
}
15+
16+
public func accessIntTwice() {
17+
var x = 0
18+
takesInoutAndEscaping(&x, escapeClosure({ x = 3 }))
19+
}
20+
21+
// accessIntTwice()
22+
// CHECK-LABEL: sil @$s26access_enforcement_options0A8IntTwiceyyF : $@convention(thin) () -> () {
23+
// CHECK: [[BOX:%.*]] = alloc_box ${ var Int }, var, name "x"
24+
// CHECK: [[PROJ:%.*]] = project_box [[BOX]] : ${ var Int }, 0
25+
// NONE: [[ACCESS:%.*]] = begin_access [modify] [dynamic] [[PROJ]] : $*Int
26+
// OPT: [[ACCESS:%.*]] = begin_access [modify] [dynamic] [[PROJ]] : $*Int
27+
// UNCHECKED-NOT: = begin_access
28+
// CHECK-LABEL: } // end sil function '$s26access_enforcement_options0A8IntTwiceyyF'
29+
30+
// closure #1 in accessIntTwice()
31+
// CHECK-LABEL: sil private @$s26access_enforcement_options0A8IntTwiceyyFyycfU_ : $@convention(thin) (@guaranteed { var Int }) -> () {
32+
// CHECK: bb0(%0 : ${ var Int }):
33+
// CHECK: [[PROJ:%.*]] = project_box %0 : ${ var Int }, 0
34+
// NONE: [[ACCESS:%.*]] = begin_access [modify] [dynamic] [[PROJ]] : $*Int
35+
// OPT: [[ACCESS:%.*]] = begin_access [modify] [dynamic] [no_nested_conflict] [[PROJ]] : $*Int
36+
// UNCHECKED-NOT: = begin_access
37+
// CHECK-LABEL: } // end sil function '$s26access_enforcement_options0A8IntTwiceyyFyycfU_'

test/SILOptimizer/access_marker_elim.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-sil-opt -enforce-exclusivity=unchecked -emit-sorted-sil -access-marker-elim %s | %FileCheck %s --check-prefix=UNCHECKED
2-
// FIXME: %target-sil-opt -enforce-exclusivity=checked -emit-sorted-sil -access-marker-elim %s | %FileCheck %s --check-prefix=CHECKED
2+
// RUN: %target-sil-opt -enforce-exclusivity=checked -emit-sorted-sil -access-marker-elim %s | %FileCheck %s --check-prefix=CHECKED
33

44
sil_stage raw
55

@@ -78,7 +78,7 @@ bb0:
7878
// UNCHECKED-LABEL: } // end sil function 'f020_boxArg'
7979
//
8080
// CHECKED-LABEL: sil hidden @f020_boxArg : $@convention(thin) (@owned { var Builtin.Int64 }) -> () {
81-
// CHECKED: bb0(%0 : ${ var Builtin.Int64 }):
81+
// CHECKED: bb0(%0 : @owned ${ var Builtin.Int64 }):
8282
// CHECKED: [[ADR:%.*]] = project_box %0 : ${ var Builtin.Int64 }, 0
8383
// CHECKED: [[VAL:%.*]] = integer_literal $Builtin.Int64, 42
8484
// CHECKED: [[ACCESS:%.*]] = begin_access [modify] [unknown] [[ADR]]

0 commit comments

Comments
 (0)