[clang-tools-extra] r246039 - Fix another LoopConvert fail.

Angel Garcia Gomez via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 26 10:08:25 PDT 2015


Author: angelgarcia
Date: Wed Aug 26 12:08:24 2015
New Revision: 246039

URL: http://llvm.org/viewvc/llvm-project?rev=246039&view=rev
Log:
Fix another LoopConvert fail.

Summary: Prevent LoopConvert from taking as alias anything that comes from a random member function call.

Reviewers: alexfh

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D12370

Modified:
    clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
    clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp?rev=246039&r1=246038&r2=246039&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp Wed Aug 26 12:08:24 2015
@@ -368,8 +368,14 @@ static bool isAliasDecl(const Decl *TheD
     break;
   }
 
-  case Stmt::CXXMemberCallExprClass:
-    return true;
+  case Stmt::CXXMemberCallExprClass: {
+    const auto *MemCall = cast<CXXMemberCallExpr>(Init);
+    if (MemCall->getMethodDecl()->getName() == "at") {
+      assert(MemCall->getNumArgs() == 1);
+      return isIndexInSubscriptExpr(MemCall->getArg(0), IndexVar);
+    }
+    return false;
+  }
 
   default:
     break;

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp?rev=246039&r1=246038&r2=246039&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp Wed Aug 26 12:08:24 2015
@@ -207,11 +207,17 @@ void refs_and_vals() {
   for (dependent<int>::iterator it = dep.begin(), e = dep.end(); it != e; ++it) {
     printf("%d\n", *it);
     const int& idx = other[0];
+    unsigned othersize = other.size();
   }
-  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : dep)
   // CHECK-FIXES-NEXT: printf("%d\n", elem);
   // CHECK-FIXES-NEXT: const int& idx = other[0];
+  // CHECK-FIXES-NEXT: unsigned othersize = other.size();
+
+  for (int i = 0, e = dep.size(); i != e; ++i) {
+    int idx = other.at(i);
+  }
 }
 
 } // namespace NamingAlias




More information about the cfe-commits mailing list