Fix reborrow verifier to look through borrowed from

This commit is contained in:
Meghana Gupta
2024-12-16 10:23:18 -08:00
parent 252a57a3fd
commit 4cab04e190
2 changed files with 32 additions and 2 deletions

View File

@@ -1604,10 +1604,15 @@ void swift::visitExtendedReborrowPhiBaseValuePairs(
// the reborrow, its phi value will be the new base value.
for (auto &op : phiOp.getBranch()->getAllOperands()) {
PhiOperand otherPhiOp(&op);
if (otherPhiOp.getSource() != currentBaseValue) {
auto *borrowedFromUser = getBorrowedFromUser(currentBaseValue);
if (borrowedFromUser && borrowedFromUser == otherPhiOp.getSource()) {
newBaseValue = otherPhiOp.getValue();
continue;
}
if (otherPhiOp.getSource() == currentBaseValue) {
newBaseValue = otherPhiOp.getValue();
continue;
}
newBaseValue = otherPhiOp.getValue();
}
// Call the visitor function

View File

@@ -334,3 +334,28 @@ bb3(%phi1 : @guaranteed $Wrapper2, %phi2 : @guaranteed $Wrapper1):
%9999 = tuple()
return %9999 : $()
}
sil hidden [ossa] @borrowed_from_reborrow : $@convention(thin) (@inout Klass) -> () {
bb0(%0 : $*Klass):
%1 = load_borrow %0
%2 = begin_borrow [lexical] %1
br bb1(%1, %2)
bb1(%4 : @reborrow $Klass, %5 : @reborrow $Klass):
%6 = borrowed %5 from (%4)
%7 = borrowed %4 from ()
br bb2(%7, %6)
bb2(%9 : @reborrow $Klass, %10 : @reborrow $Klass):
%11 = borrowed %10 from (%9)
%12 = borrowed %9 from ()
br bb3(%12, %11)
bb3(%14 : @reborrow $Klass, %15 : @reborrow $Klass):
%16 = borrowed %15 from (%14)
%17 = borrowed %14 from ()
end_borrow %16
end_borrow %17
%20 = tuple ()
return %20
}