[LLVMdev] ReplaceInstWithInst appears to invalidate BB iterator?

Duncan Sands baldrick at free.fr
Sat May 7 05:35:16 PDT 2011


Hi Justin,

> I have a call to ReplaceInstWithInst(Instruction *From, Instruction *To) inside of a for loop iterating through a BasicBlock::iterator.  On the very next pass after I replace the instruction, the iterator appears to be invalidated.  Is this supposed to happen or am I doing something silly?  Is there a more appropriate way to do this?  Thanks,

since ReplaceInstWithInst deletes (i.e. frees) the instruction "From", any
iterators referring to From will be invalidated.

Ciao, Duncan.



More information about the llvm-dev mailing list