Check that iterator I is not the end iterator.
authorAkira Hatanaka <ahatanaka@mips.com>
Wed, 31 Oct 2012 00:50:52 +0000 (00:50 +0000)
committerAkira Hatanaka <ahatanaka@mips.com>
Wed, 31 Oct 2012 00:50:52 +0000 (00:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167086 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/MachineInstr.cpp

index e8885761db26e9ead5e013239f6fa7956cc9a0a1..ce8d52000b47949716bf37c50315f2250e0517a3 100644 (file)
@@ -1015,9 +1015,10 @@ MachineInstr::getRegClassConstraint(unsigned OpIdx,
 unsigned MachineInstr::getBundleSize() const {
   assert(isBundle() && "Expecting a bundle");
 
-  MachineBasicBlock::const_instr_iterator I = *this;
+  const MachineBasicBlock *MBB = getParent();
+  MachineBasicBlock::const_instr_iterator I = *this, E = MBB->instr_end();
   unsigned Size = 0;
-  while ((++I)->isInsideBundle()) {
+  while ((++I != E) && I->isInsideBundle()) {
     ++Size;
   }
   assert(Size > 1 && "Malformed bundle");