Fix read after free found by valgrind.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52309 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng 2008-06-16 07:34:17 +00:00
parent 58dcb0e0cd
commit 7a15391c8d

View File

@ -1026,19 +1026,15 @@ bool LocalSpiller::CommuteToFoldReload(MachineBasicBlock &MBB,
DefMI->getOperand(DefIdx).getReg() == SrcReg);
// Now commute def instruction.
MachineInstr *CommutedMI = TII->commuteInstruction(DefMI);
MachineInstr *CommutedMI = TII->commuteInstruction(DefMI, true);
if (!CommutedMI)
return false;
SmallVector<unsigned, 2> Ops;
Ops.push_back(NewDstIdx);
MachineInstr *FoldedMI = TII->foldMemoryOperand(MF, CommutedMI, Ops, SS);
if (!FoldedMI) {
if (CommutedMI == DefMI)
TII->commuteInstruction(CommutedMI);
else
MBB.erase(CommutedMI);
delete CommutedMI; // Not needed since foldMemoryOperand returns new MI.
if (!FoldedMI)
return false;
}
VRM.addSpillSlotUse(SS, FoldedMI);
VRM.virtFolded(VirtReg, FoldedMI, VirtRegMap::isRef);
@ -1052,17 +1048,16 @@ bool LocalSpiller::CommuteToFoldReload(MachineBasicBlock &MBB,
MII = MBB.insert(MII, FoldedMI); // Update MII to backtrack.
// Delete all 3 old instructions.
InvalidateKills(MI, RegKills, KillOps);
VRM.RemoveMachineInstrFromMaps(&MI);
MBB.erase(&MI);
if (CommutedMI != DefMI)
MBB.erase(CommutedMI);
InvalidateKills(*DefMI, RegKills, KillOps);
VRM.RemoveMachineInstrFromMaps(DefMI);
MBB.erase(DefMI);
InvalidateKills(*ReloadMI, RegKills, KillOps);
VRM.RemoveMachineInstrFromMaps(ReloadMI);
MBB.erase(ReloadMI);
InvalidateKills(*DefMI, RegKills, KillOps);
VRM.RemoveMachineInstrFromMaps(DefMI);
MBB.erase(DefMI);
InvalidateKills(MI, RegKills, KillOps);
VRM.RemoveMachineInstrFromMaps(&MI);
MBB.erase(&MI);
++NumCommutes;
return true;
}