Skip to content

Commit 960619b

Browse files
committed
Fix ClosureLifetimeFixup's copy elimination for noncopyable values
On finding unrecognized user, reset `initialization` of the stack so that we don't inadvertently eliminate copy
1 parent 179a125 commit 960619b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/SILOptimizer/Mandatory/ClosureLifetimeFixup.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ static SILValue tryRewriteToPartialApplyStack(
775775
CopyAddrInst *initialization = nullptr;
776776
MarkDependenceInst *markDep = nullptr;
777777
for (auto *use : stack->getUses()) {
778+
auto *user = use->getUser();
778779
// Since we removed the `dealloc_stack`s from the capture arguments,
779780
// the only uses of this stack slot should be the initialization, the
780781
// partial application, and possibly a mark_dependence from the
@@ -840,7 +841,13 @@ static SILValue tryRewriteToPartialApplyStack(
840841
initialization = possibleInit;
841842
continue;
842843
}
844+
if (isa<DebugValueInst>(user) || isa<DestroyAddrInst>(user) ||
845+
isa<DeallocStackInst>(user)) {
846+
continue;
847+
}
843848
LLVM_DEBUG(llvm::dbgs() << "-- unrecognized use\n");
849+
// Reset initialization on an unrecognized use
850+
initialization = nullptr;
844851
break;
845852
}
846853
if (!initialization) {

0 commit comments

Comments
 (0)