mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -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
|
||||
|
||||
26
test/SIL/verifier-no-fail-access-scope3.sil
Normal file
26
test/SIL/verifier-no-fail-access-scope3.sil
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user