[llvm] r208282 - SCEV: Use I = vector<>.erase(I) to iterate and delete at the same time
Tobias Grosser
tobias at grosser.es
Thu May 8 00:53:44 PDT 2014
On 08/05/2014 09:51, Hal Finkel wrote:
> ----- Original Message -----
>> From: "Tobias Grosser" <tobias at grosser.es>
>> To: llvm-commits at cs.uiuc.edu
>> Sent: Thursday, May 8, 2014 2:12:45 AM
>> Subject: [llvm] r208282 - SCEV: Use I = vector<>.erase(I) to iterate and delete at the same time
>>
>> Author: grosser
>> Date: Thu May 8 02:12:44 2014
>> New Revision: 208282
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=208282&view=rev
>> Log:
>> SCEV: Use I = vector<>.erase(I) to iterate and delete at the same
>> time
>>
>> Modified:
>> llvm/trunk/lib/Analysis/ScalarEvolution.cpp
>>
>> Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=208282&r1=208281&r2=208282&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
>> +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Thu May 8 02:12:44
>> 2014
>> @@ -7223,12 +7223,9 @@ static void findArrayDimensionsRec(Scala
>> Terms[I] = Q;
>> }
>>
>> - // Remove all SCEVConstants.
>> - for (unsigned I = 0; I < Terms.size();)
>> - if (isa<SCEVConstant>(Terms[I]))
>> - Terms.erase(Terms.begin() + I);
>> - else
>> - ++I;
>> + for (auto I = Terms.begin(), E = Terms.end(); I != E; I++)
>> + if (isa<SCEVConstant>(*I))
>> + I = Terms.erase(I);
>
> I'm pretty sure this is wrong. For one thing, if you erase something, and don't update E, then you'll step off the end of the vector. Also, when you erase something, I is updated to point to the next element, so you don't want to execute I++ again after the iteration is finished (so if you have two constants in a row, you'll erase only the first). Please fix this (or revert it).
You are right. It even fails test cases, which I for some reason missed.
I will revert it.
Tobias
More information about the llvm-commits
mailing list