SIL: be more tolerant when a user is deleted during use-list iteration.

Check if an operand's instruction has been deleted in `UseList.next()`.
This allows to delete an instruction, which has two uses of a value, during use-list iteration.
This commit is contained in:
Erik Eckstein
2025-02-17 09:14:31 +01:00
parent 67f312cc2f
commit 48db89031a
6 changed files with 96 additions and 3 deletions

View File

@@ -105,8 +105,16 @@ public struct UseList : CollectionLikeSequence {
var currentOpPtr: OptionalBridgedOperand
public mutating func next() -> Operand? {
if let op = currentOpPtr.operand {
currentOpPtr = op.getNextUse()
if let bridgedOp = currentOpPtr.operand {
var op = bridgedOp
// Skip operands of deleted instructions.
while op.isDeleted() {
guard let nextOp = op.getNextUse().operand else {
return nil
}
op = nextOp
}
currentOpPtr = op.getNextUse();
return Operand(bridged: op)
}
return nil