https://github.com/zeyi2 updated https://github.com/llvm/llvm-project/pull/228547
>From ffbc7f5c2967c73b5c160a3a448a3e7f6f9b4bf1 Mon Sep 17 00:00:00 2001 From: Zeyi Xu <[email protected]> Date: Sat, 3 Oct 2026 02:26:20 +0800 Subject: [PATCH 1/2] [clang-tidy][NFC] Move isOutOfLine matcher into utils::Matchers Co-authored-by: Cursor <[email protected]> --- .../bugprone/DerivedMethodShadowingBaseMethodCheck.cpp | 6 ++---- .../clang-tidy/modernize/UseEqualsDefaultCheck.cpp | 5 +---- .../performance/TriviallyDestructibleCheck.cpp | 10 ++++------ clang-tools-extra/clang-tidy/utils/Matchers.h | 2 ++ 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp index 904685cb8416d0..4fdb65d7505d32 100644 --- a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp @@ -7,10 +7,12 @@ //===----------------------------------------------------------------------===// #include "DerivedMethodShadowingBaseMethodCheck.h" +#include "../utils/Matchers.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/ASTMatchers/ASTMatchers.h" using namespace clang::ast_matchers; +using namespace clang::tidy::matchers; namespace clang::tidy::bugprone { @@ -77,10 +79,6 @@ AST_MATCHER(CXXMethodDecl, nameCollidesWithMethodInBase) { return false; } -// Same as clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp, -// similar matchers are used elsewhere in LLVM -AST_MATCHER(CXXMethodDecl, isOutOfLine) { return Node.isOutOfLine(); } - AST_MATCHER(CXXMethodDecl, isTemplate) { return Node.getDescribedFunctionTemplate() != nullptr; } diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp index 1535fa79676abf..2032e543641eff 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp @@ -15,6 +15,7 @@ #include <optional> using namespace clang::ast_matchers; +using namespace clang::tidy::matchers; namespace clang::tidy::modernize { @@ -217,10 +218,6 @@ void UseEqualsDefaultCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "IgnoreMacros", IgnoreMacros); } -namespace { -AST_MATCHER(CXXMethodDecl, isOutOfLine) { return Node.isOutOfLine(); } -} // namespace - void UseEqualsDefaultCheck::registerMatchers(MatchFinder *Finder) { // Skip unions/union-like classes since their constructors behave differently // when defaulted vs. empty. diff --git a/clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp b/clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp index 5088cfb7ca5035..f3034f9e9eb469 100644 --- a/clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp @@ -20,12 +20,6 @@ namespace clang::tidy::performance { namespace { -// We use isOutOfLine() to find out-of-line defaulted destructor definitions. -// This is more robust than !isFirstDecl() because with C++20 modules, when a -// class is visible through both a header include and a module import, its -// declarations may appear multiple times in the redeclaration chain. -AST_MATCHER(CXXMethodDecl, isOutOfLine) { return Node.isOutOfLine(); } - AST_MATCHER_P(CXXRecordDecl, hasBase, Matcher<QualType>, InnerMatcher) { return llvm::any_of(Node.bases(), [&](const CXXBaseSpecifier &BaseSpec) { return InnerMatcher.matches(BaseSpec.getType(), Finder, Builder); @@ -34,6 +28,10 @@ AST_MATCHER_P(CXXRecordDecl, hasBase, Matcher<QualType>, InnerMatcher) { } // namespace +// We use isOutOfLine() to find out-of-line defaulted destructor definitions. +// This is more robust than !isFirstDecl() because with C++20 modules, when a +// class is visible through both a header include and a module import, its +// declarations may appear multiple times in the redeclaration chain. void TriviallyDestructibleCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( cxxDestructorDecl( diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.h b/clang-tools-extra/clang-tidy/utils/Matchers.h index e04da473226239..e137a78d9650ce 100644 --- a/clang-tools-extra/clang-tidy/utils/Matchers.h +++ b/clang-tools-extra/clang-tidy/utils/Matchers.h @@ -22,6 +22,8 @@ AST_MATCHER(BinaryOperator, isRelationalOperator) { AST_MATCHER(BinaryOperator, isEqualityOperator) { return Node.isEqualityOp(); } +AST_MATCHER(Decl, isOutOfLine) { return Node.isOutOfLine(); } + AST_MATCHER(QualType, isExpensiveToCopy) { std::optional<bool> IsExpensive = utils::type_traits::isExpensiveToCopy(Node, Finder->getASTContext()); >From c6854a49f23909c4145e24a42f860d050db6e231 Mon Sep 17 00:00:00 2001 From: Zeyi Xu <[email protected]> Date: Thu, 29 Oct 2026 19:58:09 +0800 Subject: [PATCH 2/2] ~ --- .../clang-tidy/modernize/UseEqualsDefaultCheck.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp index 2032e543641eff..989fbb8c7be376 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp @@ -50,8 +50,8 @@ getAllDirectBases(const CXXRecordDecl *Record) { /// Returns a matcher that matches member expressions where the base is /// the variable declared as \p Var and the accessed member is the one declared /// as \p Field. -static internal::Matcher<Expr> accessToFieldInVar(const FieldDecl *Field, - const ValueDecl *Var) { +static ast_matchers::internal::Matcher<Expr> +accessToFieldInVar(const FieldDecl *Field, const ValueDecl *Var) { return ignoringImpCasts( memberExpr(hasObjectExpression(declRefExpr(to(varDecl(equalsNode(Var))))), member(fieldDecl(equalsNode(Field))))); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
