Fix store_borrow multi block handling in mem2reg

This commit is contained in:
Meghana Gupta
2022-08-30 12:44:11 -07:00
parent 04f1cde82e
commit 17664c0c60
2 changed files with 24 additions and 4 deletions

View File

@@ -420,8 +420,8 @@ beginLexicalLifetimeAfterStore(AllocStackInst *asi, SILInstruction *inst) {
if (isGuaranteedLexicalValue(sbi->getSrc())) {
return {{stored, SILValue(), SILValue()}, /*isStorageValid*/ true};
}
auto *borrow = SILBuilderWithScope(sbi).createBeginBorrow(
loc, stored, /*isLexical*/ true);
auto *borrow = SILBuilderWithScope(sbi->getNextInstruction())
.createBeginBorrow(loc, stored, /*isLexical*/ true);
return {{stored, borrow, SILValue()}, /*isStorageValid*/ true};
}
BeginBorrowInst *bbi = nullptr;
@@ -794,6 +794,11 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
if (!sbi) {
continue;
}
if (sbi->getDest() != asi) {
continue;
}
assert(!deinitializationPoints[blockPromotingWithin]);
deinitializationPoints[blockPromotingWithin] = inst;
if (!runningVals.hasValue()) {
continue;
}
@@ -802,8 +807,6 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
}
// Mark storage as invalid and mark end_borrow as a deinit point.
runningVals->isStorageValid = false;
assert(!deinitializationPoints[blockPromotingWithin]);
deinitializationPoints[blockPromotingWithin] = inst;
if (!canEndLexicalLifetime(runningVals->value)) {
continue;
}