[PATCH] D12370: Fix another LoopConvert fail.

Angel Garcia via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 26 09:44:04 PDT 2015


angelgarcia created this revision.
angelgarcia added a reviewer: alexfh.
angelgarcia added subscribers: cfe-commits, klimek.

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

http://reviews.llvm.org/D12370

Files:
  clang-tidy/modernize/LoopConvertUtils.cpp
  test/clang-tidy/modernize-loop-convert-extra.cpp

Index: test/clang-tidy/modernize-loop-convert-extra.cpp
===================================================================
--- test/clang-tidy/modernize-loop-convert-extra.cpp
+++ test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -207,11 +207,17 @@
   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
Index: clang-tidy/modernize/LoopConvertUtils.cpp
===================================================================
--- clang-tidy/modernize/LoopConvertUtils.cpp
+++ clang-tidy/modernize/LoopConvertUtils.cpp
@@ -368,8 +368,14 @@
     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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12370.33215.patch
Type: text/x-patch
Size: 1542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150826/eb8c41f9/attachment.bin>


More information about the cfe-commits mailing list