[LLVMdev] Why the fault?

Mark Schimmel Mark.Schimmel at synopsys.com
Tue Mar 31 18:47:35 PDT 2015

  for (BasicBlock::reverse_iterator I = BB.rbegin(), E = BB.rend(); I != E; ) {

    Instruction& inst = *I;

    ++I; <-- iterator should be advanced to the previous instruction

    // Happens to be an Instruction::SExt.
    // Works fine if I iterate forwards
    if (isInstructionTriviallyDead(&inst, TLI))

Sorry for the inexperienced question, but I'm confused why this works when using a forward iterator, but fails in reverse. The iterator is moved off the current instruction so why would erasing the current instruction cause an error?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150401/1430f2a1/attachment.html>

More information about the llvm-dev mailing list