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

Daniel Jasper djasper at google.com
Mon Jan 12 05:17:56 PST 2015


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.

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;





More information about the cfe-commits mailing list