https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/132016

>From 0d4f53cefc223a116b25f9106d37dc707c58ec0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= <carlos.gal...@zenseact.com>
Date: Wed, 19 Mar 2025 12:28:49 +0000
Subject: [PATCH] [clang-tidy] Skip system macros in
 readability-identifier-naming check

Currently, the check is processing system macros. Most importantly,
it tries to find .clang-tidy files associated with those files, if
the option GetConfigPerFile (on by default) is active.

This is problematic for a number of reasons:

- System macros cannot be acted upon (renamed), so it's wasted work.
- When the main .cpp file includes a system header, clang-tidy tries
  to find the .clang-tidy file for that system header. When that system
  header is a 3rd-party repository, they may have their own .clang-tidy
  file, which may not be compatible with the current version of
  clang-tidy. So, clang-tidy may fail to analyze our main.cpp file,
  only because it includes a 3rd-party system header whose .clang-tidy
  file is incompatible with our clang-tidy binary.

Therefore, skip system macros in this check.
---
 .../clang-tidy/utils/RenamerClangTidyCheck.cpp              | 6 +++++-
 clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h  | 3 +++
 clang-tools-extra/docs/ReleaseNotes.rst                     | 4 ++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index 9104723c7f1c0..b8cf14c20ea2e 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -194,6 +194,8 @@ class RenamerClangTidyCheckPPCallbacks : public PPCallbacks 
{
       return;
     if (SM.isWrittenInCommandLineFile(MacroNameTok.getLocation()))
       return;
+    if (Check->skipSystemMacros() && 
SM.isInSystemHeader(MacroNameTok.getLocation()))
+      return;
     Check->checkMacro(MacroNameTok, Info, SM);
   }
 
@@ -397,7 +399,9 @@ RenamerClangTidyCheck::RenamerClangTidyCheck(StringRef 
CheckName,
                                              ClangTidyContext *Context)
     : ClangTidyCheck(CheckName, Context),
       AggressiveDependentMemberLookup(
-          Options.get("AggressiveDependentMemberLookup", false)) {}
+          Options.get("AggressiveDependentMemberLookup", false)),
+      SkipSystemMacros(!Context->getOptions().SystemHeaders.value_or(false))
+    {}
 RenamerClangTidyCheck::~RenamerClangTidyCheck() = default;
 
 void RenamerClangTidyCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
index 3d5721b789ac2..5f59d14bf370e 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
@@ -118,6 +118,8 @@ class RenamerClangTidyCheck : public ClangTidyCheck {
   void addUsage(const NamedDecl *Decl, SourceRange Range,
                 const SourceManager &SourceMgr);
 
+  bool skipSystemMacros() const { return SkipSystemMacros; }
+
 protected:
   /// Overridden by derived classes, returns information about if and how a 
Decl
   /// failed the check. A 'std::nullopt' result means the Decl did not fail the
@@ -162,6 +164,7 @@ class RenamerClangTidyCheck : public ClangTidyCheck {
 
   NamingCheckFailureMap NamingCheckFailures;
   const bool AggressiveDependentMemberLookup;
+  const bool SkipSystemMacros;
 };
 
 } // namespace tidy
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 72aa05eb4dcd1..205655c59c48c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -188,6 +188,10 @@ Changes in existing checks
   tolerating fix-it breaking compilation when functions is used as pointers
   to avoid matching usage of functions within the current compilation unit.
 
+- Improved :doc:`readability-identifier-naming
+  <clang-tidy/checks/readability/identifier-naming>` to avoid processing system
+  macros (unless the `SystemHeaders` option is enabled).
+
 Removed checks
 ^^^^^^^^^^^^^^
 

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to