Skip to content

Commit c1e6096

Browse files
committed
Fix findOwnershipReferenceRoot to stop at BeginBorrow.
Useful for finding the borrow scope enclosing an address.
1 parent 6079cbe commit c1e6096

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ bool swift::isLetAddress(SILValue address) {
367367

368368
bool swift::isIdentityPreservingRefCast(SingleValueInstruction *svi) {
369369
// Ignore both copies and other identity and ownership preserving casts
370-
return isa<CopyValueInst>(svi) ||
371-
isIdentityAndOwnershipPreservingRefCast(svi);
370+
return isa<CopyValueInst>(svi) || isa<BeginBorrowInst>(svi)
371+
|| isIdentityAndOwnershipPreservingRefCast(svi);
372372
}
373373

374374
// On some platforms, casting from a metatype to a reference type dynamically
@@ -385,8 +385,6 @@ bool swift::isIdentityAndOwnershipPreservingRefCast(
385385
switch (svi->getKind()) {
386386
default:
387387
return false;
388-
// Ignore borrows
389-
case SILInstructionKind::BeginBorrowInst:
390388
// Ignore class type casts
391389
case SILInstructionKind::UpcastInst:
392390
case SILInstructionKind::UncheckedRefCastInst:
@@ -479,7 +477,7 @@ SILValue swift::findOwnershipReferenceRoot(SILValue ref) {
479477
// MARK: AccessedStorage
480478
//===----------------------------------------------------------------------===//
481479

482-
SILGlobalVariable *getReferencedGlobal(SILInstruction *inst) {
480+
static SILGlobalVariable *getReferencedGlobal(SILInstruction *inst) {
483481
if (auto *gai = dyn_cast<GlobalAddrInst>(inst)) {
484482
return gai->getReferencedGlobal();
485483
}

0 commit comments

Comments
 (0)