[clang] 7284e0f - [clang] mangle placeholder for deduced type as a template-prefix (#106335)

via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 29 14:53:06 PDT 2024


Author: Matheus Izvekov
Date: 2024-08-29T18:53:03-03:00
New Revision: 7284e0f3a4f8924a0f69f654db8c4b4d00d232cb

URL: https://github.com/llvm/llvm-project/commit/7284e0f3a4f8924a0f69f654db8c4b4d00d232cb
DIFF: https://github.com/llvm/llvm-project/commit/7284e0f3a4f8924a0f69f654db8c4b4d00d232cb.diff

LOG: [clang] mangle placeholder for deduced type as a template-prefix (#106335)

As agreed on https://github.com/itanium-cxx-abi/cxx-abi/issues/109 these
placeholders should be mangled as a `template-prefix` production.

```
    <template-prefix> ::= <template unqualified-name>           # global template
                      ::= <prefix> <template unqualified-name>  # nested template
                      ::= <template-param>                      # template template parameter
                      ::= <substitution>
```

Previous to this patch, the template template parameter case was not
handled, and template template parameters were incorrectly being handled
as unqualified-names.

Before #95202, DeducedTemplateType was not canonicalized correctly, so
that template template parameter declarations were retained
uncanonicalized.

After #95202, they are correctly canonicalized, but this now leads to
these TTPs being anonymous entities, where the mangling implementation
correctly doesn't expect an anonymous declaration of this kind, leading
to a crash.

Fixes #106182.

Added: 
    clang/test/CodeGenCXX/GH106182.cpp
    clang/test/SemaCXX/GH106182.cpp

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/AST/ItaniumMangle.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 27f3d6e05da9f5..d3aebdb0b06477 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -326,6 +326,8 @@ Bug Fixes to C++ Support
 - Fix evaluation of the index of dependent pack indexing expressions/types specifiers (#GH105900)
 - Correctly handle subexpressions of an immediate invocation in the presence of implicit casts. (#GH105558)
 - Clang now correctly handles direct-list-initialization of a structured bindings from an array. (#GH31813)
+- Mangle placeholders for deduced types as a template-prefix, such that mangling
+  of template template parameters uses the correct production. (#GH106182)
 - Fixed an assertion failure when converting vectors to int/float with invalid expressions. (#GH105486)
 
 Bug Fixes to AST Handling

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 976670d1efa561..1ce51f65dabd75 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -4442,14 +4442,10 @@ void CXXNameMangler::mangleType(const DeducedTemplateSpecializationType *T) {
   if (!Deduced.isNull())
     return mangleType(Deduced);
 
-  TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl();
-  assert(TD && "shouldn't form deduced TST unless we know we have a template");
-
-  if (mangleSubstitution(TD))
-    return;
-
-  mangleName(GlobalDecl(TD));
-  addSubstitution(TD);
+  TemplateName TN = T->getTemplateName();
+  assert(TN.getAsTemplateDecl() &&
+         "shouldn't form deduced TST unless we know we have a template");
+  mangleType(TN);
 }
 
 void CXXNameMangler::mangleType(const AtomicType *T) {

diff  --git a/clang/test/CodeGenCXX/GH106182.cpp b/clang/test/CodeGenCXX/GH106182.cpp
new file mode 100644
index 00000000000000..401dadfd6de8b7
--- /dev/null
+++ b/clang/test/CodeGenCXX/GH106182.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++20 %s -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s
+
+template <template <class> class S>
+void create_unique()
+  requires (S{0}, true) {}
+
+template <class Fn> struct A {
+  constexpr A(Fn) {};
+};
+
+template void create_unique<A>();
+// CHECK: @_Z13create_uniqueI1AEvvQcmtlT_Li0EELb1E(

diff  --git a/clang/test/SemaCXX/GH106182.cpp b/clang/test/SemaCXX/GH106182.cpp
new file mode 100644
index 00000000000000..f82064bff27e9e
--- /dev/null
+++ b/clang/test/SemaCXX/GH106182.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template <class Fn> struct A {
+  constexpr A(Fn) {};
+};
+
+template <template <class> class S>
+ void create_unique()
+   requires (S{0}, true);
+
+template <template <class> class S>
+ void create_unique()
+   requires (S{0}, true) {}
+
+template void create_unique<A>();


        


More information about the cfe-commits mailing list