summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngel Garcia Gomez <angelgarcia@google.com>2015-08-26 17:08:24 +0000
committerAngel Garcia Gomez <angelgarcia@google.com>2015-08-26 17:08:24 +0000
commit8409e88fdef77a4970b067706d24cd70a347aadd (patch)
tree80e6a94ea04ec5d63fa05d54ea73021d4a852276
parentbf891b12b4a8fe0e64f89101e1d4ff451de923ec (diff)
downloadbcm5719-llvm-8409e88fdef77a4970b067706d24cd70a347aadd.tar.gz
bcm5719-llvm-8409e88fdef77a4970b067706d24cd70a347aadd.zip
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 llvm-svn: 246039
-rw-r--r--clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp10
-rw-r--r--clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp8
2 files changed, 15 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index 0058ea6ba60..ace0aee3114 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -368,8 +368,14 @@ static bool isAliasDecl(const Decl *TheDecl, const VarDecl *IndexVar) {
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;
diff --git a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp
index 85711b6e560..4095d1057dd 100644
--- a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp
+++ b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -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
OpenPOWER on IntegriCloud