Skip to content

Commit 77b463c

Browse files
committed
[clang-tidy] Avoid expensive AST traversal in RedundantTypenameCheck
In Fuchsia, we have several files that take over 2 hours for this check to run, where as it only takes 8 seconds to finish without the RedundantTypenameCheck. We can avoid this exponential behavior by limiting the use of hasAncestor to typeLocs for the types that are actually used in the checking logic. From the wall time for the check with --enable-profile goes from 6724 seconds (about 2 hours) to down to a reasonable 0.1753 seconds.
1 parent 540fd18 commit 77b463c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ using namespace clang::ast_matchers;
1818
namespace clang::tidy::readability {
1919

2020
void RedundantTypenameCheck::registerMatchers(MatchFinder *Finder) {
21-
Finder->addMatcher(typeLoc(unless(hasAncestor(decl(isInstantiated()))))
22-
.bind("nonDependentTypeLoc"),
23-
this);
21+
Finder->addMatcher(
22+
typeLoc(loc(TypeMatcher(anyOf(typedefType(), tagType(),
23+
deducedTemplateSpecializationType(),
24+
templateSpecializationType()))),
25+
unless(hasAncestor(decl(isInstantiated()))))
26+
.bind("nonDependentTypeLoc"),
27+
this);
2428

2529
if (!getLangOpts().CPlusPlus20)
2630
return;

0 commit comments

Comments
 (0)