SIL-Verifier: Don't verify that there are no stores in read-only access scopes if there is a conflicting scope

This is a programming error, but the compiler should not crash. The violation is caught at runtime.
This commit is contained in:
Erik Eckstein
2025-12-01 13:18:27 +01:00
parent 290bcb5423
commit 9ceb8b83c1
2 changed files with 36 additions and 1 deletions

View File

@@ -258,6 +258,15 @@ private struct MutatingUsesWalker : AddressDefUseWalker {
}
}
mutating func walkDown(address: Operand, path: UnusedWalkingPath) -> WalkResult {
if let beginAccess = address.instruction as? BeginAccessInst, beginAccess.accessKind != .read {
// Don't verify that there are no stores in read-only access scopes if there is a conflicting scope.
// This is a programming error, but the compiler should not crash. The violation is caught at runtime.
return .continueWalk
}
return walkDownDefault(address: address, path: path)
}
mutating func leafUse(address: Operand, path: UnusedWalkingPath) -> WalkResult {
if address.isMutatedAddress {
mutatingInstructions.insert(address.instruction)
@@ -288,7 +297,7 @@ private extension Operand {
{
switch convention {
case .indirectIn, .indirectInGuaranteed:
// Such operands are consumed by the `partial_apply` and therefore cound as "written".
// Such operands are consumed by the `partial_apply` and therefore count as "written".
return true
default:
return false

View File

@@ -0,0 +1,26 @@
// RUN: %target-sil-opt %s -o /dev/null
// REQUIRES: asserts
sil_stage canonical
// Don't verify that there are no stores in read-only access scopes if there is a conflicting scope.
// This is a programming error, but the compiler should not crash. The violation is caught at runtime.
import Builtin
import Swift
sil_global @g : $Int
sil [ossa] @write_in_read_only_scope : $@convention(thin) (Int) -> () {
bb0(%0 : $Int):
%1 = global_addr @g : $*Int
%2 = begin_access [read] [dynamic] %1
%3 = begin_access [modify] [dynamic] %1
store %0 to [trivial] %3
end_access %3
end_access %2
%7 = tuple()
return %7
}