[clang] [clang-tools-extra] [ast matcher] use `Matcher<QualType>` instead of `DynTypedMatcher` in `TypeLocTypeMatcher` (PR #123450)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 17 22:02:18 PST 2025


https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/123450

There are no template in `TypeLocTypeMatcher`. So we do not need to use `DynTypedMatcher` which can improve performance


>From 959949cd5170a538e1c93d00366014f6aaf3a232 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Sat, 18 Jan 2025 14:00:31 +0800
Subject: [PATCH] [ast matcher] use `Matcher<QualType>` instead of
 `DynTypedMatcher` in

There are no template in
---
 clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 1 +
 clang/include/clang/ASTMatchers/ASTMatchersInternal.h       | 5 ++---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 1ff61bae46b1ed..4448e9ccba80d9 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 1f7b5e7cac8465..55a925bf869091 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1804,7 +1804,7 @@ class LocMatcher : public MatcherInterface<TLoc> {
 ///
 /// Used to implement the \c loc() matcher.
 class TypeLocTypeMatcher : public MatcherInterface<TypeLoc> {
-  DynTypedMatcher InnerMatcher;
+  Matcher<QualType> InnerMatcher;
 
 public:
   explicit TypeLocTypeMatcher(const Matcher<QualType> &InnerMatcher)
@@ -1814,8 +1814,7 @@ class TypeLocTypeMatcher : public MatcherInterface<TypeLoc> {
                BoundNodesTreeBuilder *Builder) const override {
     if (!Node)
       return false;
-    return this->InnerMatcher.matches(DynTypedNode::create(Node.getType()),
-                                      Finder, Builder);
+    return this->InnerMatcher.matches(Node.getType(), Finder, Builder);
   }
 };
 



More information about the cfe-commits mailing list