Author: Carlos Galvez
Date: 2025-08-02T12:20:25+02:00
New Revision: 0e40051565db1399b573b4bddc43c806ca86dc8d

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

LOG: [clang-tidy] Skip declarations in system headers in RenamerClangTidyC… 
(#151772)

…heck

One typically only wants to perform renaming operations in user code,
not in system headers (which are out of the user's control). Let's skip
those altogether.

This leads to performance improvements in clang-tidy. As a benchmark, I
run all checks on a .cpp file that #includes all C++ standard headers.

On trunk:

```
Suppressed 213362 warnings (213362 in non-user code).

real    0m14.422s
user    0m14.236s
sys     0m0.184s
```

On this patch:

```
Suppressed 75411 warnings (75411 in non-user code).

real    0m12.472s
user    0m12.334s
sys     0m0.136s
```

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 dd28806e008ed..eaa04fef08c43 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -432,6 +432,10 @@ RenamerClangTidyCheck::addUsage(
   if (FixLocation.isInvalid())
     return {NamingCheckFailures.end(), false};
 
+  // Skip if in system system header
+  if (SourceMgr.isInSystemHeader(FixLocation))
+    return {NamingCheckFailures.end(), false};
+
   auto EmplaceResult = NamingCheckFailures.try_emplace(FailureId);
   NamingCheckFailure &Failure = EmplaceResult.first->second;
 
@@ -455,6 +459,9 @@ RenamerClangTidyCheck::addUsage(
 void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl,
                                      SourceRange UsageRange,
                                      const SourceManager &SourceMgr) {
+  if (SourceMgr.isInSystemHeader(Decl->getLocation()))
+    return;
+
   if (hasNoName(Decl))
     return;
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index e45f870fd4330..2f720d47a0931 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -130,6 +130,10 @@ Changes in existing checks
   <clang-tidy/checks/bugprone/infinite-loop>` check by adding detection for
   variables introduced by structured bindings.
 
+- Improved :doc:`bugprone-reserved-identifier
+  <clang-tidy/checks/bugprone/reserved-identifier>` check by ignoring
+  declarations in system headers.
+
 - Improved :doc:`bugprone-signed-char-misuse
   <clang-tidy/checks/bugprone/signed-char-misuse>` check by fixing
   false positives on C23 enums with the fixed underlying type of signed char.
@@ -160,6 +164,10 @@ Changes in existing checks
   <clang-tidy/checks/portability/template-virtual-member-function>` check to
   avoid false positives on pure virtual member functions.
 
+- Improved :doc:`readability-identifier-naming
+  <clang-tidy/checks/readability/identifier-naming>` check by ignoring
+  declarations in system headers.
+
 - Improved :doc:`readability-qualified-auto
   <clang-tidy/checks/readability/qualified-auto>` check by adding the option
   `IgnoreAliasing`, that allows not looking at underlying types of type 
aliases.


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

Reply via email to