Skip to content

Commit f22f05f

Browse files
committed
Fix an assertion failure in SILMem2Reg.
The ASI->eraseFromParent() call after removeSingleBlockAllocation(ASI) will assert if there are any remaining uses of the allocation ASI. This can happen if there are any dead instructions for struct or tuple address projections, since removeSingleBlockAllocation only removes the instructions that are actually used by loads and stores. The existing stdlib/subString.swift test exposes this issue when running check-swift-optimize. rdar://problem/28671838
1 parent 7ea6feb commit f22f05f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,15 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *ASI) {
505505
break;
506506
}
507507
}
508+
509+
// Remove dead address instructions that may be uses of the allocation.
510+
while (Inst->use_empty() && (isa<StructElementAddrInst>(Inst) ||
511+
isa<TupleElementAddrInst>(Inst))) {
512+
SILValue Next = Inst->getOperand(0);
513+
Inst->eraseFromParent();
514+
NumInstRemoved++;
515+
Inst = cast<SILInstruction>(Next);
516+
}
508517
}
509518
}
510519

0 commit comments

Comments
 (0)