Skip to content

Commit 349c3f1

Browse files
authored
Merge pull request #78217 from meg-gupta/fixreborrowverify
Fix reborrow verifier to look through borrowed from
2 parents 53f16be + 4cab04e commit 349c3f1

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,10 +1604,15 @@ void swift::visitExtendedReborrowPhiBaseValuePairs(
16041604
// the reborrow, its phi value will be the new base value.
16051605
for (auto &op : phiOp.getBranch()->getAllOperands()) {
16061606
PhiOperand otherPhiOp(&op);
1607-
if (otherPhiOp.getSource() != currentBaseValue) {
1607+
auto *borrowedFromUser = getBorrowedFromUser(currentBaseValue);
1608+
if (borrowedFromUser && borrowedFromUser == otherPhiOp.getSource()) {
1609+
newBaseValue = otherPhiOp.getValue();
1610+
continue;
1611+
}
1612+
if (otherPhiOp.getSource() == currentBaseValue) {
1613+
newBaseValue = otherPhiOp.getValue();
16081614
continue;
16091615
}
1610-
newBaseValue = otherPhiOp.getValue();
16111616
}
16121617

16131618
// Call the visitor function

test/SIL/OwnershipVerifier/guaranteed_phis.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,28 @@ bb3(%phi1 : @guaranteed $Wrapper2, %phi2 : @guaranteed $Wrapper1):
334334
%9999 = tuple()
335335
return %9999 : $()
336336
}
337+
338+
sil hidden [ossa] @borrowed_from_reborrow : $@convention(thin) (@inout Klass) -> () {
339+
bb0(%0 : $*Klass):
340+
%1 = load_borrow %0
341+
%2 = begin_borrow [lexical] %1
342+
br bb1(%1, %2)
343+
344+
bb1(%4 : @reborrow $Klass, %5 : @reborrow $Klass):
345+
%6 = borrowed %5 from (%4)
346+
%7 = borrowed %4 from ()
347+
br bb2(%7, %6)
348+
349+
bb2(%9 : @reborrow $Klass, %10 : @reborrow $Klass):
350+
%11 = borrowed %10 from (%9)
351+
%12 = borrowed %9 from ()
352+
br bb3(%12, %11)
353+
354+
bb3(%14 : @reborrow $Klass, %15 : @reborrow $Klass):
355+
%16 = borrowed %15 from (%14)
356+
%17 = borrowed %14 from ()
357+
end_borrow %16
358+
end_borrow %17
359+
%20 = tuple ()
360+
return %20
361+
}

0 commit comments

Comments
 (0)