[LLVMdev] ReplaceInstWithInst appears to invalidate BB iterator?
Justin M. LaPre
laprej at cs.rpi.edu
Sat May 7 10:48:42 PDT 2011
On May 7, 2011, at 1:00 PM, llvmdev-request at cs.uiuc.edu wrote:
>
> 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.
>
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!
-Justin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110507/83845921/attachment.html>
More information about the llvm-dev
mailing list