diff --git a/lib/CodeGen/LiveDebugVariables.cpp b/lib/CodeGen/LiveDebugVariables.cpp index 41bf87fc5db..783a7e1ded0 100644 --- a/lib/CodeGen/LiveDebugVariables.cpp +++ b/lib/CodeGen/LiveDebugVariables.cpp @@ -795,7 +795,10 @@ UserValue::splitLocation(unsigned OldLocNo, ArrayRef NewRegs) { bool UserValue::splitRegister(unsigned OldReg, ArrayRef NewRegs) { bool DidChange = false; - for (unsigned LocNo = 0, E = locations.size(); LocNo != E; ++LocNo) { + // Split locations referring to OldReg. Iterate backwards so splitLocation can + // safely erase unuused locations. + for (unsigned i = locations.size(); i ; --i) { + unsigned LocNo = i-1; const MachineOperand *Loc = &locations[LocNo]; if (!Loc->isReg() || Loc->getReg() != OldReg) continue;