Skip to content

Commit 8c12e00

Browse files
authored
Merge pull request #85843 from eeckstein/fix-verifier
Don't verify that there are no stores in read-only access scopes if there is a conflicting scope
2 parents 4a664da + 9ceb8b8 commit 8c12e00

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

SwiftCompilerSources/Sources/SIL/Utilities/Verifier.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ private struct MutatingUsesWalker : AddressDefUseWalker {
258258
}
259259
}
260260

261+
mutating func walkDown(address: Operand, path: UnusedWalkingPath) -> WalkResult {
262+
if let beginAccess = address.instruction as? BeginAccessInst, beginAccess.accessKind != .read {
263+
// Don't verify that there are no stores in read-only access scopes if there is a conflicting scope.
264+
// This is a programming error, but the compiler should not crash. The violation is caught at runtime.
265+
return .continueWalk
266+
}
267+
return walkDownDefault(address: address, path: path)
268+
}
269+
261270
mutating func leafUse(address: Operand, path: UnusedWalkingPath) -> WalkResult {
262271
if address.isMutatedAddress {
263272
mutatingInstructions.insert(address.instruction)
@@ -288,7 +297,7 @@ private extension Operand {
288297
{
289298
switch convention {
290299
case .indirectIn, .indirectInGuaranteed:
291-
// Such operands are consumed by the `partial_apply` and therefore cound as "written".
300+
// Such operands are consumed by the `partial_apply` and therefore count as "written".
292301
return true
293302
default:
294303
return false
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
// RUN: %target-sil-opt %s -o /dev/null
3+
4+
// REQUIRES: asserts
5+
6+
sil_stage canonical
7+
8+
// Don't verify that there are no stores in read-only access scopes if there is a conflicting scope.
9+
// This is a programming error, but the compiler should not crash. The violation is caught at runtime.
10+
11+
import Builtin
12+
import Swift
13+
14+
sil_global @g : $Int
15+
16+
sil [ossa] @write_in_read_only_scope : $@convention(thin) (Int) -> () {
17+
bb0(%0 : $Int):
18+
%1 = global_addr @g : $*Int
19+
%2 = begin_access [read] [dynamic] %1
20+
%3 = begin_access [modify] [dynamic] %1
21+
store %0 to [trivial] %3
22+
end_access %3
23+
end_access %2
24+
%7 = tuple()
25+
return %7
26+
}

0 commit comments

Comments
 (0)