[llvm-commits] [llvm] r141665 - /llvm/trunk/lib/Target/CellSPU/SPUInstrInfo.cpp

David Blaikie dblaikie at gmail.com
Tue Oct 11 08:08:37 PDT 2011


On Tue, Oct 11, 2011 at 5:55 AM, Kalle Raiskila <kalle.raiskila at nokia.com>wrote:

> Fix a iterator out of bounds error, that triggers rarely.
>
>  for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) {
>     if (I->getOpcode() == SPU::HBRA ||
>         I->getOpcode() == SPU::HBR_LABEL){
>       I=MBB.erase(I);
> +      if (I == MBB.end())
> +        break;
>     }
>   }
>  }
>

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?

The way to make this work if that's how it should behave is:

for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ) {
  if (...)
    I = MBB.erase(I);
  else
    ++I;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20111011/881487f6/attachment.html>


More information about the llvm-commits mailing list