Skip to content

Commit f32d4be

Browse files
committed
SIL Verifier: don't run read-only access scope verification in lowered SIL
LoadableByAddress in lowered SIL can insert `copy_addr`s inside read-only access scope. rdar://163248403
1 parent 0e4dc2f commit f32d4be

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

SwiftCompilerSources/Sources/SIL/Utilities/Verifier.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,20 @@ extension LoadBorrowInst : VerifiableInstruction {
156156

157157
extension BeginAccessInst : VerifiableInstruction {
158158
func verify(_ context: VerifierContext) {
159-
if context.silStage == .raw {
160-
return
161-
}
162159
// Catch violations like
163160
// ```
164161
// %1 = begin_access [read] %0
165162
// store %2 to %0
166163
// end_access %1
167164
// ```
165+
166+
guard context.silStage == .canonical else {
167+
// Mandatory passes on raw SIL need to be completed until we can verify this.
168+
// Also, LoadableByAddress in lowered SIL can insert `copy_addr`s inside read-only access scope.
169+
// Therefore we can only run this verification in canonical SIL.
170+
return
171+
}
172+
168173
if address.type.isMoveOnly && enforcement == .static {
169174
// This is a workaround for a bug in the move-only checker: rdar://151841926.
170175
// The move-only checker sometimes inserts destroy_addr within read-only static access scopes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: not --crash %target-sil-opt %s -o /dev/null
2+
3+
// REQUIRES: asserts
4+
5+
sil_stage canonical
6+
7+
import Builtin
8+
import Swift
9+
10+
sil [ossa] @write_in_read_only_scope : $@convention(thin) (@inout Int, Int) -> () {
11+
bb0(%0 : $*Int, %1 : $Int):
12+
%2 = begin_access [read] [static] %0
13+
store %1 to [trivial] %0
14+
end_access %2
15+
%5 = tuple()
16+
return %5
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-sil-opt %s -o /dev/null
2+
3+
// REQUIRES: asserts
4+
5+
sil_stage raw
6+
7+
// Need to complete mandatory passes until we can verify that there are no stores in read-only access scopes.
8+
9+
import Builtin
10+
import Swift
11+
12+
sil [ossa] @write_in_read_only_scope : $@convention(thin) (@inout Int, Int) -> () {
13+
bb0(%0 : $*Int, %1 : $Int):
14+
%2 = begin_access [read] [static] %0
15+
store %1 to [trivial] %0
16+
end_access %2
17+
%5 = tuple()
18+
return %5
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-sil-opt %s -o /dev/null
2+
3+
// REQUIRES: asserts
4+
5+
sil_stage lowered
6+
7+
// LoadableByAddress in lowered SIL can insert copy_addrs inside read-only access scope.
8+
9+
import Builtin
10+
import Swift
11+
12+
sil [ossa] @write_in_read_only_scope : $@convention(thin) (@inout Int, Int) -> () {
13+
bb0(%0 : $*Int, %1 : $Int):
14+
%2 = begin_access [read] [static] %0
15+
store %1 to [trivial] %0
16+
end_access %2
17+
%5 = tuple()
18+
return %5
19+
}

0 commit comments

Comments
 (0)