[clang] [clang-tools-extra] Move isLocal AST matcher to ASTMatchers for reusability (PR #117521)

Marie Zhussupova via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 24 21:58:12 PST 2024


https://github.com/phychee created https://github.com/llvm/llvm-project/pull/117521

Fixes #<117431>

>From ee0c3b11c93dc8d95f521cda7c2ac9acc7c184f7 Mon Sep 17 00:00:00 2001
From: Marie Zhussupova <102762019+phychee at users.noreply.github.com>
Date: Sun, 24 Nov 2024 22:45:11 -0600
Subject: [PATCH] Move isLocal AST matcher to ASTMatchers for reusability

---
 clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp | 3 ---
 clang/include/clang/ASTMatchers/ASTMatchers.h               | 5 +++++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 71a4cee4bdc6ef..7c159d8dd8659b 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -17,9 +17,6 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::misc {
 
 namespace {
-// FIXME: This matcher exists in some other code-review as well.
-// It should probably move to ASTMatchers.
-AST_MATCHER(VarDecl, isLocal) { return Node.isLocalVarDecl(); }
 AST_MATCHER_P(DeclStmt, containsAnyDeclaration,
               ast_matchers::internal::Matcher<Decl>, InnerMatcher) {
   return ast_matchers::internal::matchesFirstInPointerRange(
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 4bcaa953a61af2..f8388028d2ccbe 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -739,6 +739,11 @@ AST_MATCHER(FunctionDecl, isMain) {
   return Node.isMain();
 }
 
+// Matches variable declarations that represent local variables.
+AST_MATCHER(VarDecl, isLocal) { 
+    return Node.isLocalVarDecl(); 
+}
+
 /// Matches the specialized template of a specialization declaration.
 ///
 /// Given



More information about the cfe-commits mailing list