[clang] [clang] mangle placeholder for deduced type as a template-prefix (PR #106335)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 27 21:08:41 PDT 2024
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/106335
>From b86ebec082a82da967528819e9df7bd16c502b34 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov <mizvekov at gmail.com>
Date: Wed, 28 Aug 2024 00:34:12 -0300
Subject: [PATCH] [clang] mangle placeholder for deduced type as a
template-prefix
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 patch, we correctly canonicalize them, but now this leads
to handling these TTPs as anonymous entities, where the implementation
correctly doesn't expect an anonymous declaration of this kind,
leading to a crash.
Fixes #106182.
---
clang/docs/ReleaseNotes.rst | 2 ++
clang/lib/AST/ItaniumMangle.cpp | 12 ++++--------
clang/test/CodeGenCXX/GH106182.cpp | 12 ++++++++++++
3 files changed, 18 insertions(+), 8 deletions(-)
create mode 100644 clang/test/CodeGenCXX/GH106182.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d9fa068c2910f4..864bd9616b71e0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -319,6 +319,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)
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(
More information about the cfe-commits
mailing list