[clang-tools-extra] 6c2eca9 - [clang-tidy] Simplify inefficient algorithm check
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 17 02:20:12 PST 2021
Author: Stephen Kelly
Date: 2021-02-17T10:19:44Z
New Revision: 6c2eca96a2a59f69889a9d4133a819ab2e4fa1ef
URL: https://github.com/llvm/llvm-project/commit/6c2eca96a2a59f69889a9d4133a819ab2e4fa1ef
DIFF: https://github.com/llvm/llvm-project/commit/6c2eca96a2a59f69889a9d4133a819ab2e4fa1ef.diff
LOG: [clang-tidy] Simplify inefficient algorithm check
The normalization of matchers means that this now works in all language
modes.
Differential Revision: https://reviews.llvm.org/D96140
Added:
Modified:
clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h
clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp b/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
index 8381ed0b1553..05ef855de7e7 100644
--- a/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
@@ -35,27 +35,24 @@ void InefficientAlgorithmCheck::registerMatchers(MatchFinder *Finder) {
"::std::unordered_set", "::std::unordered_map",
"::std::unordered_multiset", "::std::unordered_multimap"));
- const auto Matcher = traverse(
- TK_AsIs,
+ const auto Matcher =
callExpr(
callee(functionDecl(Algorithms)),
hasArgument(
- 0, cxxConstructExpr(has(ignoringParenImpCasts(cxxMemberCallExpr(
+ 0, cxxMemberCallExpr(
callee(cxxMethodDecl(hasName("begin"))),
on(declRefExpr(
hasDeclaration(decl().bind("IneffContObj")),
anyOf(hasType(ContainerMatcher.bind("IneffCont")),
hasType(pointsTo(
ContainerMatcher.bind("IneffContPtr")))))
- .bind("IneffContExpr"))))))),
+ .bind("IneffContExpr")))),
hasArgument(
- 1, cxxConstructExpr(has(ignoringParenImpCasts(cxxMemberCallExpr(
- callee(cxxMethodDecl(hasName("end"))),
- on(declRefExpr(
- hasDeclaration(equalsBoundNode("IneffContObj"))))))))),
- hasArgument(2, expr().bind("AlgParam")),
- unless(isInTemplateInstantiation()))
- .bind("IneffAlg"));
+ 1, cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end"))),
+ on(declRefExpr(hasDeclaration(
+ equalsBoundNode("IneffContObj")))))),
+ hasArgument(2, expr().bind("AlgParam")))
+ .bind("IneffAlg");
Finder->addMatcher(Matcher, this);
}
diff --git a/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h b/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h
index 14f8fbbab2ae..5a7536ad76aa 100644
--- a/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h
+++ b/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h
@@ -29,6 +29,9 @@ class InefficientAlgorithmCheck : public ClangTidyCheck {
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
};
} // namespace performance
diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp
index aa4e30d6f3fe..19a6701c5b6a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s performance-inefficient-algorithm %t
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy %s performance-inefficient-algorithm %t
namespace std {
template <typename T> struct less {
More information about the cfe-commits
mailing list