Skip to content

Commit 5dc67fa

Browse files
committed
SIL Verifier: check that the enclosing values of a borrowed-from instructions are valid
1 parent 012aa62 commit 5dc67fa

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/Verifier.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ private extension Phi {
9696

9797
extension BorrowedFromInst : VerifiableInstruction {
9898
func verify(_ context: FunctionPassContext) {
99+
100+
for ev in enclosingValues {
101+
require(ev.isValidEnclosingValueInBorrowedFrom, "invalid enclosing value in borrowed-from: \(ev)")
102+
}
103+
99104
var computedEVs = Stack<Value>(context)
100105
defer { computedEVs.deinitialize() }
101106

@@ -114,6 +119,21 @@ extension BorrowedFromInst : VerifiableInstruction {
114119
}
115120
}
116121

122+
private extension Value {
123+
var isValidEnclosingValueInBorrowedFrom: Bool {
124+
switch ownership {
125+
case .owned:
126+
return true
127+
case .guaranteed:
128+
return BeginBorrowValue(self) != nil ||
129+
self is BorrowedFromInst ||
130+
forwardingInstruction != nil
131+
case .none, .unowned:
132+
return false
133+
}
134+
}
135+
}
136+
117137
extension LoadBorrowInst : VerifiableInstruction {
118138
func verify(_ context: FunctionPassContext) {
119139
if isUnchecked {

0 commit comments

Comments
 (0)