Skip to content

[clang-tidy] Skip declarations in system headers in RenamerClangTidyC… #151772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2025

Conversation

carlosgalvezp
Copy link
Contributor

@carlosgalvezp carlosgalvezp commented Aug 1, 2025

…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

@llvmbot
Copy link
Member

llvmbot commented Aug 1, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Carlos Galvez (carlosgalvezp)

Changes

…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). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

real 0m14.517s
user 0m14.383s
sys 0m0.132s

On this patch:

Suppressed 75107 warnings (75107 in non-user code).

real 0m12.545s
user 0m12.349s
sys 0m0.188s


Full diff: https://github.com/llvm/llvm-project/pull/151772.diff

2 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp (+3)
  • (modified) clang-tools-extra/docs/ReleaseNotes.rst (+8)
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index dd28806e008ed..e7009b8f67a96 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -455,6 +455,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.

@llvmbot
Copy link
Member

llvmbot commented Aug 1, 2025

@llvm/pr-subscribers-clang-tidy

Author: Carlos Galvez (carlosgalvezp)

Changes

…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). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

real 0m14.517s
user 0m14.383s
sys 0m0.132s

On this patch:

Suppressed 75107 warnings (75107 in non-user code).

real 0m12.545s
user 0m12.349s
sys 0m0.188s


Full diff: https://github.com/llvm/llvm-project/pull/151772.diff

2 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp (+3)
  • (modified) clang-tools-extra/docs/ReleaseNotes.rst (+8)
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index dd28806e008ed..e7009b8f67a96 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -455,6 +455,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.

…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).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

real	0m14.517s
user	0m14.383s
sys	0m0.132s

On this patch:

Suppressed 75107 warnings (75107 in non-user code).

real	0m12.545s
user	0m12.349s
sys	0m0.188s
@carlosgalvezp carlosgalvezp force-pushed the readability_system_headers branch from dca6c74 to 92e6660 Compare August 1, 2025 21:38
@carlosgalvezp carlosgalvezp merged commit 0e40051 into llvm:main Aug 2, 2025
10 checks passed
@carlosgalvezp carlosgalvezp deleted the readability_system_headers branch August 2, 2025 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants