Author: Carlos Galvez
Date: 2025-08-23T21:41:05+02:00
New Revision: d7390be0646821d58d104f164c693ce7f1f970cb

URL: 
https://github.com/llvm/llvm-project/commit/d7390be0646821d58d104f164c693ce7f1f970cb
DIFF: 
https://github.com/llvm/llvm-project/commit/d7390be0646821d58d104f164c693ce7f1f970cb.diff

LOG: [clang-tidy] Skip system macros in readability-identifier-naming check 
(#132016)

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.

This reduces the amount of unwanted warnings as follows:
    
On trunk:
Suppressed 11448 warnings (11448 in non-user code).
    
With this patch:
Suppressed 4824 warnings (4824 in non-user code).
    
The runtime is pretty much unchanged.

Co-authored-by: Carlos Gálvez <carlos.gal...@zenseact.com>

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
    clang-tools-extra/docs/ReleaseNotes.rst

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index 20853dc00123c..90539eaabbe03 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 (SM.isInSystemHeader(MacroNameTok.getLocation()))
+      return;
     Check->checkMacro(MacroNameTok, Info, SM);
   }
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a489ad9ef937f..a67b1514e387c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,7 +163,7 @@ Changes in existing checks
 
 - Improved :doc:`bugprone-reserved-identifier
   <clang-tidy/checks/bugprone/reserved-identifier>` check by ignoring
-  declarations in system headers.
+  declarations and macros in system headers.
 
 - Improved :doc:`bugprone-signed-char-misuse
   <clang-tidy/checks/bugprone/signed-char-misuse>` check by fixing
@@ -229,8 +229,8 @@ Changes in existing checks
 
 - Improved :doc:`readability-identifier-naming
   <clang-tidy/checks/readability/identifier-naming>` check by ignoring
-  declarations in system headers. The documentation is also improved to
-  
diff erentiate the general options from the specific ones.
+  declarations and macros in system headers. The documentation is also improved
+  to 
diff erentiate the general options from the specific ones.
 
 - Improved :doc:`readability-qualified-auto
   <clang-tidy/checks/readability/qualified-auto>` check by adding the option


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

Reply via email to