Skip to content

Commit 0e40051

Browse files
carlosgalvezpCarlos Gálvez
andauthored
[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 <[email protected]>
1 parent eefc3d2 commit 0e40051

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ RenamerClangTidyCheck::addUsage(
432432
if (FixLocation.isInvalid())
433433
return {NamingCheckFailures.end(), false};
434434

435+
// Skip if in system system header
436+
if (SourceMgr.isInSystemHeader(FixLocation))
437+
return {NamingCheckFailures.end(), false};
438+
435439
auto EmplaceResult = NamingCheckFailures.try_emplace(FailureId);
436440
NamingCheckFailure &Failure = EmplaceResult.first->second;
437441

@@ -455,6 +459,9 @@ RenamerClangTidyCheck::addUsage(
455459
void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl,
456460
SourceRange UsageRange,
457461
const SourceManager &SourceMgr) {
462+
if (SourceMgr.isInSystemHeader(Decl->getLocation()))
463+
return;
464+
458465
if (hasNoName(Decl))
459466
return;
460467

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ Changes in existing checks
130130
<clang-tidy/checks/bugprone/infinite-loop>` check by adding detection for
131131
variables introduced by structured bindings.
132132

133+
- Improved :doc:`bugprone-reserved-identifier
134+
<clang-tidy/checks/bugprone/reserved-identifier>` check by ignoring
135+
declarations in system headers.
136+
133137
- Improved :doc:`bugprone-signed-char-misuse
134138
<clang-tidy/checks/bugprone/signed-char-misuse>` check by fixing
135139
false positives on C23 enums with the fixed underlying type of signed char.
@@ -160,6 +164,10 @@ Changes in existing checks
160164
<clang-tidy/checks/portability/template-virtual-member-function>` check to
161165
avoid false positives on pure virtual member functions.
162166

167+
- Improved :doc:`readability-identifier-naming
168+
<clang-tidy/checks/readability/identifier-naming>` check by ignoring
169+
declarations in system headers.
170+
163171
- Improved :doc:`readability-qualified-auto
164172
<clang-tidy/checks/readability/qualified-auto>` check by adding the option
165173
`IgnoreAliasing`, that allows not looking at underlying types of type aliases.

0 commit comments

Comments
 (0)