[clang-tools-extra] r225629 - Make LoopConvert work with containers that are used like arrays.

Daniel Jasper djasper at google.com
Mon Jan 12 09:44:13 PST 2015


Thanks for checking. I'll look into it. Do you have specific examples?

On Mon, Jan 12, 2015 at 6:41 PM, David Blaikie <dblaikie at gmail.com> wrote:

>
>
> On Mon, Jan 12, 2015 at 5:17 AM, Daniel Jasper <djasper at google.com> wrote:
>
>> Author: djasper
>> Date: Mon Jan 12 07:17:56 2015
>> New Revision: 225629
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=225629&view=rev
>> Log:
>> Make LoopConvert work with containers that are used like arrays.
>>
>
> Are these transformations classified as 'risky' in some way? These sort of
> loops appear in a few places in LLVM deliberately because we're adding
> elements to the sequence as we're iterating - so we check size each time
> through and we access the vector with [] because its buffer might've been
> invalidated by new insertions. (even with size() accessed once and cached,
> we sometimes do this to visit pre-existing elements and ignore newly added
> elements - which would still be broken by a transformation to
> range-based-for/iterators)
>
>
>>
>> Modified:
>>     clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopActions.cpp
>>
>> clang-tools-extra/trunk/test/clang-modernize/LoopConvert/naming-alias.cpp
>>
>> Modified:
>> clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopActions.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopActions.cpp?rev=225629&r1=225628&r2=225629&view=diff
>>
>> ==============================================================================
>> --- clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopActions.cpp
>> (original)
>> +++ clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopActions.cpp
>> Mon Jan 12 07:17:56 2015
>> @@ -450,9 +450,16 @@ static bool isAliasDecl(const Decl *TheD
>>        const CXXOperatorCallExpr *OpCall =
>> cast<CXXOperatorCallExpr>(Init);
>>        if (OpCall->getOperator() == OO_Star)
>>          return isDereferenceOfOpCall(OpCall, IndexVar);
>> +      if (OpCall->getOperator() == OO_Subscript) {
>> +        assert(OpCall->getNumArgs() == 2);
>> +        return true;
>> +      }
>>        break;
>>    }
>>
>> +  case Stmt::CXXMemberCallExprClass:
>> +    return true;
>> +
>>    default:
>>      break;
>>    }
>>
>> Modified:
>> clang-tools-extra/trunk/test/clang-modernize/LoopConvert/naming-alias.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-modernize/LoopConvert/naming-alias.cpp?rev=225629&r1=225628&r2=225629&view=diff
>>
>> ==============================================================================
>> ---
>> clang-tools-extra/trunk/test/clang-modernize/LoopConvert/naming-alias.cpp
>> (original)
>> +++
>> clang-tools-extra/trunk/test/clang-modernize/LoopConvert/naming-alias.cpp
>> Mon Jan 12 07:17:56 2015
>> @@ -7,6 +7,8 @@
>>  const int N = 10;
>>
>>  Val Arr[N];
>> +dependent<Val> v;
>> +dependent<Val> *pv;
>>  Val &func(Val &);
>>  void sideEffect(int);
>>
>> @@ -50,6 +52,25 @@ void aliasing() {
>>    // CHECK-NEXT: int y = t.x;
>>    // CHECK-NEXT: int z = elem.x + t.x;
>>
>> +  // The same for pseudo-arrays like std::vector<T> (or here
>> dependent<Val>)
>> +  // which provide a subscript operator[].
>> +  for (int i = 0; i < v.size(); ++i) {
>> +    Val &t = v[i]; { }
>> +    int y = t.x;
>> +  }
>> +  // CHECK: for (auto & t : v)
>> +  // CHECK-NEXT: { }
>> +  // CHECK-NEXT: int y = t.x;
>> +
>> +  // The same with a call to at()
>> +  for (int i = 0; i < pv->size(); ++i) {
>> +    Val &t = pv->at(i); { }
>> +    int y = t.x;
>> +  }
>> +  // CHECK: for (auto & t : *pv)
>> +  // CHECK-NEXT: { }
>> +  // CHECK-NEXT: int y = t.x;
>> +
>>    for (int i = 0; i < N; ++i) {
>>      Val &t = func(Arr[i]);
>>      int y = t.x;
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150112/9a70338f/attachment.html>


More information about the cfe-commits mailing list