diff options
| author | Evan Cheng <evan.cheng@apple.com> | 2008-06-16 07:34:17 +0000 |
|---|---|---|
| committer | Evan Cheng <evan.cheng@apple.com> | 2008-06-16 07:34:17 +0000 |
| commit | 51c75c0c95a19e750e71eece8cda65406622e334 (patch) | |
| tree | 3bebbd7e5f1098a68aff4a1b93ef76df861896ad /llvm/lib/CodeGen/VirtRegMap.cpp | |
| parent | 03553bb59af15fbbc49a162cab2314095f674bd5 (diff) | |
| download | bcm5719-llvm-51c75c0c95a19e750e71eece8cda65406622e334.tar.gz bcm5719-llvm-51c75c0c95a19e750e71eece8cda65406622e334.zip | |
Fix read after free found by valgrind.
llvm-svn: 52309
Diffstat (limited to 'llvm/lib/CodeGen/VirtRegMap.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/VirtRegMap.cpp | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/llvm/lib/CodeGen/VirtRegMap.cpp b/llvm/lib/CodeGen/VirtRegMap.cpp index 1406748e317..220a8ec084a 100644 --- a/llvm/lib/CodeGen/VirtRegMap.cpp +++ b/llvm/lib/CodeGen/VirtRegMap.cpp @@ -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; } |

