ReplaceInstWithInst appears to invalidate BB iterator?

Hello,

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,

-Justin

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.