mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
AllocStackToBox: fix a bug which results in a too early released captured variable
In case of a borrowed `alloc_box`, the optimization didn't look through the `begin_borrow` when calculating the final release of the box. This resulted in inserting the destroy of the inserted `alloc_stack` too early. rdar://97087762
This commit is contained in:
@@ -53,9 +53,9 @@ static llvm::cl::opt<bool> AllocBoxToStackAnalyzeApply(
|
||||
// SIL Utilities for alloc_box Promotion
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
static SILValue stripOffCopyValue(SILValue V) {
|
||||
while (auto *CVI = dyn_cast<CopyValueInst>(V)) {
|
||||
V = CVI->getOperand();
|
||||
static SILValue stripOffCopyAndBorrow(SILValue V) {
|
||||
while (isa<CopyValueInst>(V) || isa<BeginBorrowInst>(V)) {
|
||||
V = cast<SingleValueInstruction>(V)->getOperand(0);
|
||||
}
|
||||
return V;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ static bool addLastRelease(SILValue V, SILBasicBlock *BB,
|
||||
for (auto I = BB->rbegin(); I != BB->rend(); ++I) {
|
||||
if (isa<StrongReleaseInst>(*I) || isa<DeallocBoxInst>(*I) ||
|
||||
isa<DestroyValueInst>(*I)) {
|
||||
if (stripOffCopyValue(I->getOperand(0)) != V)
|
||||
if (stripOffCopyAndBorrow(I->getOperand(0)) != V)
|
||||
continue;
|
||||
|
||||
Releases.push_back(&*I);
|
||||
|
||||
Reference in New Issue
Block a user