summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorNate Begeman <natebegeman@mac.com>2005-06-12 23:50:33 +0000
committerNate Begeman <natebegeman@mac.com>2005-06-12 23:50:33 +0000
commit02e33b70b1cc05671714bf27e5a2661eaa77840f (patch)
tree320bfbb1b720e7daf9ee46a385cd407331f7c44e /llvm/lib
parent1609a541cd8bf1feacb8984274612396627a9be5 (diff)
downloadbcm5719-llvm-02e33b70b1cc05671714bf27e5a2661eaa77840f.tar.gz
bcm5719-llvm-02e33b70b1cc05671714bf27e5a2661eaa77840f.zip
Fix a memory smasher caught by Mac OS X's debug malloc library. We were
incorrectly using an iterator after it was invalid. llvm-svn: 22207
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/PowerPC/PowerPCBranchSelector.cpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/llvm/lib/Target/PowerPC/PowerPCBranchSelector.cpp b/llvm/lib/Target/PowerPC/PowerPCBranchSelector.cpp
index 5eaf38f0188..c6e87410286 100644
--- a/llvm/lib/Target/PowerPC/PowerPCBranchSelector.cpp
+++ b/llvm/lib/Target/PowerPC/PowerPCBranchSelector.cpp
@@ -86,7 +86,14 @@ namespace {
for (MachineBasicBlock::iterator MBBI = MBB->begin(), EE = MBB->end();
MBBI != EE; ++MBBI) {
- if (MBBI->getOpcode() == PPC::COND_BRANCH) {
+ // We may end up deleting the MachineInstr that MBBI points to, so
+ // remember its opcode now so we can refer to it after calling erase()
+ unsigned OpcodeToReplace = MBBI->getOpcode();
+
+ if (OpcodeToReplace == PPC::COND_BRANCH) {
+ MachineBasicBlock::iterator MBBJ = MBBI;
+ ++MBBJ;
+
// condbranch operands:
// 0. CR0 register
// 1. bc opcode
@@ -101,17 +108,21 @@ namespace {
unsigned Opcode = MBBI->getOperand(1).getImmedValue();
unsigned Inverted = PPC32InstrInfo::invertPPCBranchOpcode(Opcode);
- MachineInstr *MI = MBBI;
if (Displacement >= -32768 && Displacement <= 32767) {
- BuildMI(*MBB, MBBI, Opcode, 2).addReg(PPC::CR0).addMBB(trueMBB);
+ BuildMI(*MBB, MBBJ, Opcode, 2).addReg(PPC::CR0).addMBB(trueMBB);
} else {
- BuildMI(*MBB, MBBI, Inverted, 2).addReg(PPC::CR0).addSImm(8);
- BuildMI(*MBB, MBBI, PPC::B, 1).addMBB(trueMBB);
- BuildMI(*MBB, MBBI, PPC::B, 1).addMBB(falseMBB);
+ BuildMI(*MBB, MBBJ, Inverted, 2).addReg(PPC::CR0).addSImm(8);
+ BuildMI(*MBB, MBBJ, PPC::B, 1).addMBB(trueMBB);
+ BuildMI(*MBB, MBBJ, PPC::B, 1).addMBB(falseMBB);
}
- MBB->erase(MI);
+
+ // Erase the psuedo COND_BRANCH instruction, and then back up the
+ // iterator so that when the for loop increments it, we end up in
+ // the correct place rather than iterating off the end.
+ MBB->erase(MBBI);
+ MBBI = --MBBJ;
}
- ByteCount += bytesForOpcode(MBBI->getOpcode());
+ ByteCount += bytesForOpcode(OpcodeToReplace);
}
}
OpenPOWER on IntegriCloud