<br><br><div class="gmail_quote">On Tue, Oct 11, 2011 at 5:55 AM, Kalle Raiskila <span dir="ltr"><<a href="mailto:kalle.raiskila@nokia.com">kalle.raiskila@nokia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Fix a iterator out of bounds error, that triggers rarely.<br><br> for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) {<br>
     if (I->getOpcode() == SPU::HBRA ||<br>
         I->getOpcode() == SPU::HBR_LABEL){<br>
       I=MBB.erase(I);<br>
+      if (I == MBB.end())<br>
+        break;<br>
     }<br>
   }<br>
 }<br></blockquote><div><br>Is it OK that this algorithm skips any element just after the one it removed? Or is it possible that two elements that satisfy the removal condition could be adjacent & should both be removed? <br>
<br>The way to make this work if that's how it should behave is:<br><br>for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ) {<br>  if (...)<br>    I = MBB.erase(I);<br>  else<br>    ++I;<br>}<br></div>
</div>