steveire created this revision. steveire added reviewers: aaron.ballman, njames93. Herald added subscribers: nullptr.cpp, xazax.hun. steveire requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
The normalization of matchers means that this now works in all language modes. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D96140 Files: 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 Index: clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp +++ 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 { Index: clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h =================================================================== --- clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h +++ clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h @@ -29,6 +29,9 @@ } 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 Index: clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp +++ clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp @@ -35,27 +35,24 @@ "::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); }
Index: clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp +++ 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 { Index: clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h =================================================================== --- clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h +++ clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h @@ -29,6 +29,9 @@ } 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 Index: clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp +++ clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp @@ -35,27 +35,24 @@ "::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); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits