diff mbox series

[pushed] c++: mangle multiple levels of template parms [PR109422]

Message ID 20231010212305.121636-1-jason@redhat.com
State New
Headers show
Series [pushed] c++: mangle multiple levels of template parms [PR109422] | expand

Commit Message

Jason Merrill Oct. 10, 2023, 9:23 p.m. UTC
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

This becomes be more important with concepts, but can also be seen with
generic lambdas.

	PR c++/109422

gcc/cp/ChangeLog:

	* mangle.cc (write_template_param): Also mangle level.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/lambda-generic-mangle1.C: New test.
	* g++.dg/cpp2a/lambda-generic-mangle1a.C: New test.
---
 gcc/cp/mangle.cc                                    | 13 +++++++++++++
 gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1.C |  9 +++++++++
 .../g++.dg/cpp2a/lambda-generic-mangle1a.C          | 10 ++++++++++
 3 files changed, 32 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1.C
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1a.C


base-commit: aaa5a5318adbefe87c1b781b8a3e5fc332e661ec
diff mbox series

Patch

diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc
index d88c779bfa2..d079f724910 100644
--- a/gcc/cp/mangle.cc
+++ b/gcc/cp/mangle.cc
@@ -3921,6 +3921,7 @@  static void
 write_template_param (const tree parm)
 {
   int parm_index;
+  int level;
 
   MANGLE_TRACE_TREE ("template-parm", parm);
 
@@ -3930,10 +3931,12 @@  write_template_param (const tree parm)
     case TEMPLATE_TEMPLATE_PARM:
     case BOUND_TEMPLATE_TEMPLATE_PARM:
       parm_index = TEMPLATE_TYPE_IDX (parm);
+      level = TEMPLATE_TYPE_LEVEL (parm);
       break;
 
     case TEMPLATE_PARM_INDEX:
       parm_index = TEMPLATE_PARM_IDX (parm);
+      level = TEMPLATE_PARM_LEVEL (parm);
       break;
 
     default:
@@ -3941,6 +3944,16 @@  write_template_param (const tree parm)
     }
 
   write_char ('T');
+  if (level > 1)
+    {
+      if (abi_warn_or_compat_version_crosses (19))
+	G.need_abi_warning = 1;
+      if (abi_version_at_least (19))
+	{
+	  write_char ('L');
+	  write_compact_number (level - 1);
+	}
+    }
   /* NUMBER as it appears in the mangling is (-1)-indexed, with the
      earliest template param denoted by `_'.  */
   write_compact_number (parm_index);
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1.C
new file mode 100644
index 00000000000..0051307f53d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1.C
@@ -0,0 +1,9 @@ 
+// PR c++/109422
+// { dg-do compile { target c++20 } }
+
+struct C {
+  template<typename T>
+  void f(decltype([](T, auto) { return 0; })) {}
+};
+void g() { C().f<int>({}); }
+// { dg-final { scan-assembler "_ZN1C1fIiEEvDTtlNS_UlT_TL0__E_EEE" } }
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1a.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1a.C
new file mode 100644
index 00000000000..dc7b0125631
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1a.C
@@ -0,0 +1,10 @@ 
+// PR c++/109422
+// { dg-do compile { target c++20 } }
+// { dg-additional-options "-fabi-version=18" }
+
+struct C {
+  template<typename T>
+  void f(decltype([](T, auto) { return 0; })) {}
+};
+void g() { C().f<int>({}); }
+// { dg-final { scan-assembler "_ZN1C1fIiEEvDTtlNS_UlT_T_E_EEE" } }