[llvm] r236249 - MachineVerifier: Don't crash if MachineOperand has no parent
Matt Arsenault
Matthew.Arsenault at amd.com
Thu Apr 30 12:35:41 PDT 2015
Author: arsenm
Date: Thu Apr 30 14:35:41 2015
New Revision: 236249
URL: http://llvm.org/viewvc/llvm-project?rev=236249&view=rev
Log:
MachineVerifier: Don't crash if MachineOperand has no parent
If you somehow added a MachineOperand to an instruction
that did not have the parent set, the verifier would
crash since it attempts to use the operand's parent.
Modified:
llvm/trunk/lib/CodeGen/MachineVerifier.cpp
Modified: llvm/trunk/lib/CodeGen/MachineVerifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineVerifier.cpp?rev=236249&r1=236248&r2=236249&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineVerifier.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineVerifier.cpp Thu Apr 30 14:35:41 2015
@@ -329,8 +329,18 @@ bool MachineVerifier::runOnMachineFuncti
} else if (!CurBundle)
report("No bundle header", MBBI);
visitMachineInstrBefore(MBBI);
- for (unsigned I = 0, E = MBBI->getNumOperands(); I != E; ++I)
- visitMachineOperand(&MBBI->getOperand(I), I);
+ for (unsigned I = 0, E = MBBI->getNumOperands(); I != E; ++I) {
+ const MachineInstr &MI = *MBBI;
+ const MachineOperand &Op = MI.getOperand(I);
+ if (Op.getParent() != &MI) {
+ // Make sure to use correct addOperand / RmeoveOperand / ChangeTo
+ // functions when replacing operands of a MachineInstr.
+ report("Instruction has operand with wrong parent set", &MI);
+ }
+
+ visitMachineOperand(&Op, I);
+ }
+
visitMachineInstrAfter(MBBI);
// Was this the last bundled instruction?
More information about the llvm-commits
mailing list