[llvm] r208282 - SCEV: Use I = vector<>.erase(I) to iterate and delete at the same time

Hal Finkel hfinkel at anl.gov
Thu May 8 00:51:39 PDT 2014


----- 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).

 -Hal

>  
>    if (Terms.size() > 0)
>      findArrayDimensionsRec(SE, Terms, Sizes, Zero, One);
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory



More information about the llvm-commits mailing list