Justin M. LaPre
2011-May-07 17:48 UTC
[LLVMdev] ReplaceInstWithInst appears to invalidate BB iterator?
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>
Duncan Sands
2011-May-08 16:28 UTC
[LLVMdev] ReplaceInstWithInst appears to invalidate BB iterator?
Hi Justin,> 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!instructions contain pointers to the next and previous instructions; an iterator is just a pointer to an instruction that advances by looking at the value of the instructions "next" pointer. IIRC. Ciao, Duncan.