https://github.com/adamtheturtle updated https://github.com/llvm/llvm-project/pull/235714
>From 80b1357e4af60d46962d090832496b06a43f5610 Mon Sep 17 00:00:00 2001 From: Adam Dangoor <[email protected]> Date: Mon, 26 Oct 2026 11:25:17 +0000 Subject: [PATCH 1/2] [clang][Sema] Visit repeated ADL template arguments once Fixes https://github.com/llvm/llvm-project/issues/235704 Assisted-by: OpenAI Codex --- clang/lib/Sema/SemaLookup.cpp | 13 ++++++++++--- .../SemaCXX/adl-repeated-template-arguments.cpp | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 clang/test/SemaCXX/adl-repeated-template-arguments.cpp diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 75cad0bb433f89..d6f3b4152c8c0a 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -2906,6 +2906,10 @@ namespace { return ClassesTransitive.insert(RD); } + bool visitTemplateArguments(CXXRecordDecl *RD) { + return ClassesWithVisitedTemplateArguments.insert(RD); + } + Sema &S; Sema::AssociatedNamespaceSet &Namespaces; Sema::AssociatedClassSet &Classes; @@ -2913,6 +2917,7 @@ namespace { private: Sema::AssociatedClassSet ClassesTransitive; + Sema::AssociatedClassSet ClassesWithVisitedTemplateArguments; }; } // end anonymous namespace @@ -3089,9 +3094,11 @@ addAssociatedClassesAndNamespaces(AssociatedLookup &Result, // Add the associated namespace for this class. CollectEnclosingNamespace(Result.Namespaces, Ctx); - const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); - for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I) - addAssociatedClassesAndNamespaces(Result, TemplateArgs[I]); + if (Result.visitTemplateArguments(Class)) { + const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); + for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I) + addAssociatedClassesAndNamespaces(Result, TemplateArgs[I]); + } } // Add the class itself. If we've already transitively visited this class, diff --git a/clang/test/SemaCXX/adl-repeated-template-arguments.cpp b/clang/test/SemaCXX/adl-repeated-template-arguments.cpp new file mode 100644 index 00000000000000..d29f748b4c8dbe --- /dev/null +++ b/clang/test/SemaCXX/adl-repeated-template-arguments.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s +// expected-no-diagnostics + +namespace assoc { +struct Leaf {}; +template<class T, class U=T> struct Node {}; +void consume(...); +} +void test(assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Node<assoc::Leaf>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> value) { consume(value); } + +template<class T> struct Base {}; +namespace other { struct Tag {}; } +struct Derived : Base<other::Tag> {}; +namespace other { +constexpr int select(Derived, Base<Tag>) { return 7; } +} +static_assert(select(Derived{}, Base<other::Tag>{}) == 7); >From 68947da33b8bb07d100ea2ca2fb2e078cb976535 Mon Sep 17 00:00:00 2001 From: Adam Dangoor <[email protected]> Date: Fri, 30 Oct 2026 10:28:57 +0000 Subject: [PATCH 2/2] [clang][Sema] Address ADL performance review comments Inline the visited-template-argument set insertion and document the ADL compile-time fix in the Clang release notes. Assisted-by: OpenAI Codex --- clang/docs/ReleaseNotes.md | 3 +++ clang/lib/Sema/SemaLookup.cpp | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 44f30666457f94..f3c0612bf7e8eb 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -889,6 +889,9 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and type. (#GH204756) #### Bug Fixes to C++ Support +- Fixed exponential compile time during argument-dependent lookup for nested + class template specializations with repeated template arguments. (#GH235704) + - Instantiate constexpr functions as needed before they are evaluated. (#GH73232) (#GH35052) (#GH100897) - Fixed lambdas with specifiers or attributes after the capture list being diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index d6f3b4152c8c0a..cec9b5ec12b9d5 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -2906,18 +2906,14 @@ namespace { return ClassesTransitive.insert(RD); } - bool visitTemplateArguments(CXXRecordDecl *RD) { - return ClassesWithVisitedTemplateArguments.insert(RD); - } - Sema &S; Sema::AssociatedNamespaceSet &Namespaces; Sema::AssociatedClassSet &Classes; SourceLocation InstantiationLoc; + Sema::AssociatedClassSet ClassesWithVisitedTemplateArguments; private: Sema::AssociatedClassSet ClassesTransitive; - Sema::AssociatedClassSet ClassesWithVisitedTemplateArguments; }; } // end anonymous namespace @@ -3094,7 +3090,7 @@ addAssociatedClassesAndNamespaces(AssociatedLookup &Result, // Add the associated namespace for this class. CollectEnclosingNamespace(Result.Namespaces, Ctx); - if (Result.visitTemplateArguments(Class)) { + if (Result.ClassesWithVisitedTemplateArguments.insert(Class)) { const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I) addAssociatedClassesAndNamespaces(Result, TemplateArgs[I]); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
