<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On May 7, 2011, at 1:00 PM, <a href="mailto:llvmdev-request@cs.uiuc.edu">llvmdev-request@cs.uiuc.edu</a> wrote:</div><div><br></div><blockquote type="cite"><br>Hi Justin,<br><br><blockquote type="cite">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,<br></blockquote><br>since ReplaceInstWithInst deletes (i.e. frees) the instruction "From", any<br>iterators referring to From will be invalidated.<br><br>Ciao, Duncan.<br><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></blockquote><br></div><div>Thanks Duncan.  I was able to correct my code to work around that nuance.  I was under the impression that BasicBlock::iterators mapped onto something similar to an STL list which supports erasing arbitrary elements.  Thanks for the help!</div><div><br></div><div>-Justin</div><div><br></div></body></html>