[cfe-dev] More LLVM on VC2010 fun

Unai Landa ulanda at digital-legends.com
Tue Jul 24 11:19:08 PDT 2012


I know the standard, the problem is with the code, as I said the remove seems to be done in other function with no visibility of the "potentially broken" iterators.

That's why I asked if this code has owner.

Imho, the safest way to fix this is to change the code to use index and check vector size every loop, the bad thing is performance and clarity, but without a deeper understanding of this optimization Is difficult to fix.

I don't mind to change this code to use indices, if there is not any better choice.

Unai
Sent from my iPhone

On 24/07/2012, at 19:46, "Matthieu Monrocq" <matthieu.monrocq at gmail.com<mailto:matthieu.monrocq at gmail.com>> wrote:



On Tue, Jul 24, 2012 at 2:22 PM, Unai Landa <ulanda at digital-legends.com<mailto:ulanda at digital-legends.com>> wrote:
After debuging I have been able to fix the issue;


I changed 2 lines on PeepholeOptimizer.cpp
Line 410:
from: for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {

to:  for (MachineFunction::iterator I = MF.begin(); I !=MF.end(); ++I) {



And line 421

from: MII = I->begin(), MIE = I->end(); MII != MIE; ) {

to:   MII = I->begin() ; MII != I->end(); ) {



This fixes teh problem, but I suspect that it comes from OptimizeExtInstr as it seems removesome items from the vector.



I'll do a full rebuild with this change and check if this fixes my issues.



How should I manage this change? my fix, should work, but the may be the issue is located at other function, does the PeepholeOptimizer.cpp have owner?



Unai.


Note: if items are removed from a vector, then the current iterator should be reassigned to too, as in

V::iterator it = v.begin();
it = v.erase(it);

Even though for vector it is likely to still work without this (as they are probably barebone pointers under the cover), a debug version of a STL would catch the use of `it` after the call to erase with an assertion.

If you correct the loops checks, could you also take care of updating the iterator's value ?

-- Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120724/0b0d0414/attachment.html>


More information about the cfe-dev mailing list