Skip to content

Conversation

mizvekov
Copy link
Contributor

@mizvekov mizvekov commented Apr 10, 2025

This fixes a regression introduced in
#133610 which was reported here #133610 (comment)

When mangling a dependent template specialization appearing within an unresolved prefix, translate the dtst back to a dependent template name including the prefix, and mangle following the nested unresolved-type production.

There are no release notes, since this regression was never released.

This fixes a regression introduced in
#133610 (comment)
which was reported here #133610 (comment)

When mangling a dependent template specialization appearing
within an unresolved prefix, translate the dtst back to
a dependent template name including the prefix, and mangle
following the nested unresolved-type production.

There are no release notes, since this regression was never released.
@mizvekov mizvekov self-assigned this Apr 10, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Apr 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 10, 2025

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)

Changes

This fixes a regression introduced in
#133610 (comment) which was reported here #133610 (comment)

When mangling a dependent template specialization appearing within an unresolved prefix, translate the dtst back to a dependent template name including the prefix, and mangle following the nested unresolved-type production.

There are no release notes, since this regression was never released.


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

2 Files Affected:

  • (modified) clang/lib/AST/ItaniumMangle.cpp (+13-3)
  • (modified) clang/test/CodeGenCXX/mangle-template.cpp (+19-2)
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index eb25b19bbdc74..8790a5282a96b 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -1404,9 +1404,19 @@ void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier *qualifier,
     //   - a template type parameter
     //   - a template template parameter with arguments
     // In all of these cases, we should have no prefix.
-    if (qualifier->getPrefix()) {
-      mangleUnresolvedPrefix(qualifier->getPrefix(),
-                             /*recursive*/ true);
+    if (NestedNameSpecifier *Prefix = qualifier->getPrefix()) {
+      if (const auto *DTST =
+              dyn_cast<DependentTemplateSpecializationType>(type)) {
+        Out << "srN";
+        TemplateName Template = getASTContext().getDependentTemplateName(
+            {Prefix, DTST->getDependentTemplateName().getName(),
+             /*HasTemplateKeyword=*/true});
+        mangleTemplatePrefix(Template);
+        mangleTemplateArgs(Template, DTST->template_arguments());
+        break;
+      }
+      mangleUnresolvedPrefix(Prefix,
+                             /*recursive=*/true);
     } else {
       // Otherwise, all the cases want this.
       Out << "sr";
diff --git a/clang/test/CodeGenCXX/mangle-template.cpp b/clang/test/CodeGenCXX/mangle-template.cpp
index a4cb22739ac2a..365aba5989baa 100644
--- a/clang/test/CodeGenCXX/mangle-template.cpp
+++ b/clang/test/CodeGenCXX/mangle-template.cpp
@@ -70,7 +70,7 @@ namespace test7 {
     static const unsigned value = sizeof(T);
   };
 
-  template<unsigned> struct int_c { 
+  template<unsigned> struct int_c {
     typedef float type;
   };
 
@@ -92,7 +92,7 @@ namespace test8 {
     };
   };
 
-  template<unsigned> struct int_c { 
+  template<unsigned> struct int_c {
     typedef float type;
   };
 
@@ -399,3 +399,20 @@ namespace type_qualifier {
   // CHECK: @_ZN14type_qualifier1gIPiEEvDTcmcvv_ELi1EE
   template void g<int*>(int);
 }
+
+namespace unresolved_template_specialization_type {
+  template <int> struct enable_if {};
+  struct Foo {
+    static const int value = true;
+  };
+  struct HashStateBase {
+    template <typename> using is_hashable = Foo;
+  };
+  template <class> struct raw_hash_set {
+    template <typename H>
+    static enable_if<H::template is_hashable<int>::value>
+        AbslHashValue() {}
+  };
+  template enable_if<true> raw_hash_set<int>::AbslHashValue<HashStateBase>();
+  // CHECH: @_ZN39unresolved_template_specialization_type12raw_hash_setIiE13AbslHashValueINS_13HashStateBaseEEENS_9enable_ifIXsrNT_11is_hashableIiEE5valueEEEv
+} // namespace unresolved_template_specialization_type

@mizvekov mizvekov merged commit 98feb05 into main Apr 10, 2025
14 checks passed
@mizvekov mizvekov deleted the users/mizvekov/dtst-fix-mangling branch April 10, 2025 02:23
AllinLeeYL pushed a commit to AllinLeeYL/llvm-project that referenced this pull request Apr 10, 2025
…vm#135111)

This fixes a regression introduced in
llvm#133610 which was reported here
llvm#133610 (comment)

When mangling a dependent template specialization appearing within an
unresolved prefix, translate the dtst back to a dependent template name
including the prefix, and mangle following the nested unresolved-type
production.

There are no release notes, since this regression was never released.
@asmok-g
Copy link

asmok-g commented Apr 11, 2025

Heads-up: We're seeing a clang crash after this commit that is not reproducible in the patch before. working on a repro

@asmok-g
Copy link

asmok-g commented Apr 11, 2025

Note: only reproducible with modules

@usx95
Copy link
Contributor

usx95 commented Apr 16, 2025

https://godbolt.org/z/sY44dG6Ya is the reproducer. It is not super small but still should give an idea as the stack is quite similar to stuff touched by this PR.

@shafik
Copy link
Collaborator

shafik commented Apr 17, 2025

This crash is also linked to this PR: #136119

@shafik
Copy link
Collaborator

shafik commented Apr 17, 2025

https://godbolt.org/z/sY44dG6Ya is the reproducer. It is not super small but still should give an idea as the stack is quite similar to stuff touched by this PR.

Did you open a bug report? Maybe w/ reduction is ends up the same as the one I just linked to.

@shafik
Copy link
Collaborator

shafik commented Apr 17, 2025

CC @var-const

mizvekov added a commit that referenced this pull request Apr 17, 2025
This fixes a regression introduced in #133610 which was reported here #133610 (comment)
and in #136119

This redoes previous attempt in #135111

When mangling a DTST which appears in the prefix,
the template name is not actually relevant, as its
prefix is part of the nested name anyway, and a
substitution is not allowed at that position in any case.

Fixes #136119
mizvekov added a commit that referenced this pull request Apr 17, 2025
…36201)

This fixes a regression introduced in #133610 which was reported here
#133610 (comment) and in #136119

This redoes previous attempt in #135111

When mangling a DTST which appears in the prefix,
the template name is not actually relevant, as its prefix is part of the
nested name anyway, and a
substitution is not allowed at that position in any case.

Fixes #136119
@mizvekov
Copy link
Contributor Author

@usx95 that reproducer is fixed by #136201 as well.

IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…vm#136201)

This fixes a regression introduced in llvm#133610 which was reported here
llvm#133610 (comment) and in llvm#136119

This redoes previous attempt in llvm#135111

When mangling a DTST which appears in the prefix,
the template name is not actually relevant, as its prefix is part of the
nested name anyway, and a
substitution is not allowed at that position in any case.

Fixes llvm#136119
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants