aboutsummaryrefslogtreecommitdiff
path: root/clang-tidy/performance
diff options
context:
space:
mode:
authorShuai Wang <shuaiwang@google.com>2018-07-10 22:51:06 +0000
committerShuai Wang <shuaiwang@google.com>2018-07-10 22:51:06 +0000
commit7b2da74b6cf3df6bcb0b4c8362576ab31e3551b4 (patch)
treef670a3a9a6385fa3e77c707573b4c3c97dcb8078 /clang-tidy/performance
parent98129e2feb036e0f799140af47e9fee7436d7715 (diff)
Use ExprMutationAnalyzer in performance-for-range-copy
Summary: This gives better coverage to the check as ExprMutationAnalyzer is more accurate comparing to isOnlyUsedAsConst. Majority of wins come from const usage of member field, e.g.: for (auto widget : container) { // copy of loop variable if (widget.type == BUTTON) { // const usage only recognized by ExprMutationAnalyzer // ... } } Reviewers: george.karpenkov Subscribers: a.sidorin, cfe-commits Differential Revision: https://reviews.llvm.org/D48854 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@336737 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/performance')
-rw-r--r--clang-tidy/performance/ForRangeCopyCheck.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/clang-tidy/performance/ForRangeCopyCheck.cpp b/clang-tidy/performance/ForRangeCopyCheck.cpp
index 0b9dd230..2358aacb 100644
--- a/clang-tidy/performance/ForRangeCopyCheck.cpp
+++ b/clang-tidy/performance/ForRangeCopyCheck.cpp
@@ -8,7 +8,7 @@
//===----------------------------------------------------------------------===//
#include "ForRangeCopyCheck.h"
-#include "../utils/DeclRefExprUtils.h"
+#include "../utils/ExprMutationAnalyzer.h"
#include "../utils/FixItHintUtils.h"
#include "../utils/TypeTraits.h"
@@ -79,8 +79,8 @@ bool ForRangeCopyCheck::handleCopyIsOnlyConstReferenced(
utils::type_traits::isExpensiveToCopy(LoopVar.getType(), Context);
if (LoopVar.getType().isConstQualified() || !Expensive || !*Expensive)
return false;
- if (!utils::decl_ref_expr::isOnlyUsedAsConst(LoopVar, *ForRange.getBody(),
- Context))
+ if (utils::ExprMutationAnalyzer(ForRange.getBody(), &Context)
+ .isMutated(&LoopVar))
return false;
diag(LoopVar.getLocation(),
"loop variable is copied but only used as const reference; consider "