<div dir="ltr">On Tue, May 31, 2016 at 6:45 AM, Yaron Keren via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: yrnkrn<br>
Date: Tue May 31 08:45:05 2016<br>
New Revision: 271278<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=271278&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=271278&view=rev</a><br>
Log:<br>
Do not modify a std::vector while looping it.<br>
<br>
Introduced in r271244, this is probably undefined behaviour and asserts when<br>
compiled with Visual C++ debug mode.<br></blockquote><div><br></div><div>Thanks.  I was trying to build under visual studio to get a stack trace.  Once I got that, it was obvious that I was invalidating the iterator.  This change looks good to me.</div><div><br></div><div>Thanks for fixing this!</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On further note, the loop is quadratic with regard to the number of successors<br>
since removeSuccessor is linear and could probably be modified to linear time.<br>
<br>
<br>
Modified:<br>
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br>
<br>
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=271278&r1=271277&r2=271278&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=271278&r1=271277&r2=271278&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)<br>
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Tue May 31 08:45:05 2016<br>
@@ -23841,8 +23841,12 @@ X86TargetLowering::EmitSjLjDispatchBlock<br>
       Subtarget.getRegisterInfo()->getCalleeSavedRegs(MF);<br>
   for (MachineBasicBlock *MBB : InvokeBBs) {<br>
     // Remove the landing pad successor from the invoke block and replace it<br>
-    // with the new dispatch block<br>
-    for (auto MBBS : make_range(MBB->succ_rbegin(), MBB->succ_rend())) {<br>
+    // with the new dispatch block.<br>
+    // Keep a copy of Successors since it's modified inside the loop.<br>
+    SmallVector<MachineBasicBlock *, 8> Successors(MBB->succ_rbegin(),<br>
+                                                   MBB->succ_rend());<br>
+    // FIXME: Avoid quadratic complexity.<br>
+    for (auto MBBS : Successors) {<br>
       if (MBBS->isEHPad()) {<br>
         MBB->removeSuccessor(MBBS);<br>
         MBBLPads.push_back(MBBS);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Saleem Abdulrasool<br>compnerd (at) compnerd (dot) org</div>
</div></div>