<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Apr 29, 2008, at 1:22 PM, Owen Anderson wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Apr 29, 2008, at 1:36 PM, Chris Lattner wrote:</div><blockquote type="cite"><blockquote type="cite">+  for (Loop::block_iterator LI = L->block_begin(), LE = L- <br></blockquote><blockquote type="cite"><blockquote type="cite">block_end();<br></blockquote></blockquote><blockquote type="cite">+       LI != LE; ++LI) {<br></blockquote><blockquote type="cite">+    for (BasicBlock::iterator BI = (*LI)->begin(), BE = (*LI)->end();<br></blockquote><blockquote type="cite">+         BI != BE; ) {<br></blockquote><blockquote type="cite">+      Instruction* I = BI++;<br></blockquote><blockquote type="cite">+      I->eraseFromParent();<br></blockquote><blockquote type="cite">+    }<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+    (*LI)->eraseFromParent();<br></blockquote><blockquote type="cite">+  }<br></blockquote><br>You are incrementing LI after you erase *LI.<br></blockquote><br></div><div>I'm actually reasonably confident that this is safe.  I'm iterating over the loop's block list, not over the function ilist.  Erasing *LI doesn't remove LI from the loop's block list, it just makes it a pointer to freed memory.  You'll note that the next step is to remove the blocks from LoopInfo, which <i>does</i> remove them from the loop's block list, and from the block lists of any parent loops as well.</div></div></blockquote></div><br><div>You're right, thanks!</div><div><br class="webkit-block-placeholder"></div><div>-Chris</div></body></html>