Skip to content

Commit 49b4c34

Browse files
committed
[SIL] Verified addr usage of end_borrow.
1 parent 570a583 commit 49b4c34

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,6 +2243,10 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
22432243
require(
22442244
F.hasOwnership(),
22452245
"Inst with qualified ownership in a function that is not qualified");
2246+
if (EBI->getOperand()->getType().isAddress()) {
2247+
require(isa<StoreBorrowInst>(EBI->getOperand()),
2248+
"end_borrow of an address not produced by store_borrow");
2249+
}
22462250
}
22472251

22482252
void checkEndLifetimeInst(EndLifetimeInst *I) {

test/SIL/verifier_failures.sil

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-sil-opt -emit-sorted-sil -verify-continue-on-failure -o /dev/null %s 2>&1 | %FileCheck %s
2+
// REQUIRES: asserts
3+
4+
sil_stage canonical
5+
6+
import Builtin
7+
import Swift
8+
import SwiftShims
9+
10+
class C {}
11+
12+
// CHECK: Begin Error in function end_borrow_1_addr_alloc_stack
13+
// CHECK-NEXT: SIL verification failed: end_borrow of an address not produced by store_borrow
14+
sil [ossa] @end_borrow_1_addr_alloc_stack : $@convention(thin) () -> () {
15+
%addr = alloc_stack $C
16+
end_borrow %addr : $*C
17+
dealloc_stack %addr : $*C
18+
%retval = tuple ()
19+
return %retval : $()
20+
}

0 commit comments

Comments
 (0)