From 77b463c6d552b6c24d6b8dcc679a3417939c9288 Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Wed, 3 Dec 2025 11:12:51 -0800 Subject: [PATCH] [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. --- .../clang-tidy/readability/RedundantTypenameCheck.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp index 5f2519ce9d5c3..f8e576e2a14d7 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp @@ -18,9 +18,13 @@ using namespace clang::ast_matchers; namespace clang::tidy::readability { void RedundantTypenameCheck::registerMatchers(MatchFinder *Finder) { - Finder->addMatcher(typeLoc(unless(hasAncestor(decl(isInstantiated())))) - .bind("nonDependentTypeLoc"), - this); + Finder->addMatcher( + typeLoc(loc(TypeMatcher(anyOf(typedefType(), tagType(), + deducedTemplateSpecializationType(), + templateSpecializationType()))), + unless(hasAncestor(decl(isInstantiated())))) + .bind("nonDependentTypeLoc"), + this); if (!getLangOpts().CPlusPlus20) return;