-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathaccess_enforcement_noescape_error.swift
80 lines (70 loc) · 2.99 KB
/
access_enforcement_noescape_error.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// RUN: %target-swift-frontend -module-name access_enforcement_noescape -enforce-exclusivity=checked -Onone -emit-sil -swift-version 4 -verify -parse-as-library %s
// REQUIRES: asserts
// This is the subset of tests from access_enforcement_noescape.swift
// that cause compile-time errors. All the tests are organized in one
// place so it's easy to see that coverage of all the combinations of
// access patterns is exhaustive. But the ones that cause compile time
// errors are commented out in the original file and compiled here
// instead with the '-verify' option.
// Helper
func doOne(_ f: () -> ()) {
f()
}
// Helper
func doOneInout(_: ()->(), _: inout Int) {}
// Error: noescape read + write inout.
func readWriteInout() {
var x = 3
// Around the call: [modify] [static]
// Inside closure: [modify] [static]
// expected-error@+2{{overlapping accesses to 'x', but modification requires exclusive access; consider copying to a local variable}}
// expected-note@+1{{conflicting access is here}}
doOneInout({ _ = x }, &x)
}
// Error: noescape read + write inout of an inout.
func inoutReadWriteInout(x: inout Int) {
// Around the call: [modify] [static]
// Inside closure: [modify] [static]
// expected-error@+2{{overlapping accesses to 'x', but modification requires exclusive access; consider copying to a local variable}}
// expected-note@+1{{conflicting access is here}}
doOneInout({ _ = x }, &x)
}
// Error: on noescape write + write inout.
func writeWriteInout() {
var x = 3
// Around the call: [modify] [static]
// Inside closure: [modify] [static]
// expected-error@+2{{overlapping accesses to 'x', but modification requires exclusive access; consider copying to a local variable}}
// expected-note@+1{{conflicting access is here}}
doOneInout({ x = 42 }, &x)
}
// Error: on noescape write + write inout.
func inoutWriteWriteInout(x: inout Int) {
// Around the call: [modify] [static]
// Inside closure: [modify] [static]
// expected-error@+2{{overlapping accesses to 'x', but modification requires exclusive access; consider copying to a local variable}}
// expected-note@+1{{conflicting access is here}}
doOneInout({ x = 42 }, &x)
}
// Helper
func doBlockInout(_: @convention(block) ()->(), _: inout Int) {}
func readBlockWriteInout() {
var x = 3
// Around the call: [modify] [static]
// Inside closure: [read] [static]
// expected-error@+2{{overlapping accesses to 'x', but modification requires exclusive access; consider copying to a local variable}}
// expected-note@+1{{conflicting access is here}}
doBlockInout({ _ = x }, &x)
}
// Test AccessSummaryAnalysis.
//
// The captured @inout_aliasable argument to `doOne` is re-partially applied,
// then stored is a box before passing it to doBlockInout.
func noEscapeBlock() {
var x = 3
doOne {
// expected-error@+2{{overlapping accesses to 'x', but modification requires exclusive access; consider copying to a local variable}}
// expected-note@+1{{conflicting access is here}}
doBlockInout({ _ = x }, &x)
}
}