Skip to content

Commit 5f2926c

Browse files
committed
[DebugInfo] [SILCombine] Fix variable for opened existential
The type of the new variable should be opened too. If the variable has an expression modifying the type, it cannot be rewritten and is dropped.
1 parent 9c78317 commit 5f2926c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,20 @@ SILInstruction *SILCombiner::visitAllocStackInst(AllocStackInst *AS) {
653653
if (IEI && !OEI &&
654654
!IEI->getLoweredConcreteType().hasOpenedExistential()) {
655655
assert(!IEI->getLoweredConcreteType().isOpenedExistential());
656+
Builder.setCurrentDebugScope(AS->getDebugScope());
657+
auto varInfo = AS->getVarInfo();
658+
if (varInfo) {
659+
if (varInfo->Type == AS->getElementType()) {
660+
varInfo->Type = {}; // Lower the variable's type too.
661+
} else {
662+
// Cannot salvage the variable, its type has changed and its expression
663+
// cannot be rewritten.
664+
Builder.createDebugValue(AS->getLoc(), SILUndef::get(AS), *varInfo);
665+
varInfo = {};
666+
}
667+
}
656668
auto *ConcAlloc = Builder.createAllocStack(
657-
AS->getLoc(), IEI->getLoweredConcreteType(), AS->getVarInfo());
669+
AS->getLoc(), IEI->getLoweredConcreteType(), varInfo);
658670
IEI->replaceAllUsesWith(ConcAlloc);
659671
eraseInstFromFunction(*IEI);
660672

0 commit comments

Comments
 (0)