@@ -2097,17 +2097,20 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
20972097 }
20982098 }
20992099
2100- if (lexicalLifetimeEnsured (asi) && runningVals &&
2101- runningVals->isStorageValid &&
2100+ if (!runningVals || !runningVals->isStorageValid ) {
2101+ return ;
2102+ }
2103+ // There is still valid storage after visiting all instructions in this
2104+ // block which are the only instructions involving this alloc_stack.
2105+ // That can only happen if:
2106+ // - all paths from this block end in unreachable
2107+
2108+ if (lexicalLifetimeEnsured (asi) &&
21022109 runningVals->value .getStored ()->getOwnershipKind ().isCompatibleWith (
21032110 OwnershipKind::Owned)) {
2104- // There is still valid storage after visiting all instructions in this
2105- // block which are the only instructions involving this alloc_stack.
2106- // This can only happen if all paths from this block end in unreachable.
2107- //
2108- // We need to end the lexical lifetime at the last possible location, at the
2109- // boundary blocks which are the predecessors of dominance frontier
2110- // dominated by the alloc_stack.
2111+ // An owned value was stored to the alloc_stack [lexical] but never
2112+ // destroy_addr'd. Destroy it on the dominance boundary of the
2113+ // alloc_stack's parent block.
21112114 SmallVector<SILBasicBlock *, 4 > boundary;
21122115 computeDominatedBoundaryBlocks (asi->getParent (), domInfo, boundary);
21132116 for (auto *block : boundary) {
0 commit comments