]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: mangle noexcept-expr [PR70790]
authorPatrick Palka <ppalka@redhat.com>
Sat, 3 Jun 2023 13:03:27 +0000 (09:03 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sat, 3 Jun 2023 13:03:27 +0000 (09:03 -0400)
This implements noexcept(expr) mangling and demangling as per the
Itanium ABI.

PR c++/70790

gcc/cp/ChangeLog:

* mangle.cc (write_expression): Handle NOEXCEPT_EXPR.

libiberty/ChangeLog:

* cp-demangle.c (cplus_demangle_operators): Add the noexcept
operator.
(d_print_comp_inner) <case DEMANGLE_COMPONENT_UNARY>: Always
print parens around the operand of noexcept too.
* testsuite/demangle-expected: Test noexcept operator
demangling.

gcc/testsuite/ChangeLog:

* g++.dg/abi/mangle78.C: New test.

gcc/cp/mangle.cc
gcc/testsuite/g++.dg/abi/mangle78.C [new file with mode: 0644]
libiberty/cp-demangle.c
libiberty/testsuite/demangle-expected

index 826c5e76c1dfb95869c323036f555753b61b3c7f..7dab4e62bc9ee983e6a36b0b488b435855d9a6c9 100644 (file)
@@ -3402,6 +3402,11 @@ write_expression (tree expr)
       else
        write_string ("tr");
     }
+  else if (code == NOEXCEPT_EXPR)
+    {
+      write_string ("nx");
+      write_expression (TREE_OPERAND (expr, 0));
+    }
   else if (code == CONSTRUCTOR)
     {
       bool braced_init = BRACE_ENCLOSED_INITIALIZER_P (expr);
diff --git a/gcc/testsuite/g++.dg/abi/mangle78.C b/gcc/testsuite/g++.dg/abi/mangle78.C
new file mode 100644 (file)
index 0000000..63c4d77
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/70790
+// { dg-do compile { target c++11 } }
+
+template<bool B>
+struct A { };
+
+template<class T>
+void f(A<noexcept(T{})>);
+
+int main() {
+  f<int>({});
+}
+
+// { dg-final { scan-assembler "_Z1fIiEv1AIXnxtlT_EEE" } }
index f2b36bcad68bb45e852b315bf2e0446949c1ca58..18ab28fd028dcda8abb6d5b62a61f370ec46ba83 100644 (file)
@@ -1947,6 +1947,7 @@ const struct demangle_operator_info cplus_demangle_operators[] =
   { "ng", NL ("-"),         1 },
   { "nt", NL ("!"),         1 },
   { "nw", NL ("new"),       3 },
+  { "nx", NL ("noexcept"),  1 },
   { "oR", NL ("|="),        2 },
   { "oo", NL ("||"),        2 },
   { "or", NL ("|"),         2 },
@@ -5836,8 +5837,8 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
        if (code && !strcmp (code, "gs"))
          /* Avoid parens after '::'.  */
          d_print_comp (dpi, options, operand);
-       else if (code && !strcmp (code, "st"))
-         /* Always print parens for sizeof (type).  */
+       else if (code && (!strcmp (code, "st") || !strcmp (code, "nx")))
+         /* Always print parens for sizeof (type) and noexcept(expr).  */
          {
            d_append_char (dpi, '(');
            d_print_comp (dpi, options, operand);
index d9bc7ed4b1fc33fde1c683202f9e4fd7fbb7e40c..52dff883a184f2f5f066cf282946817319c9f6ad 100644 (file)
@@ -1659,3 +1659,6 @@ auto f()::{lambda<typename $T0>(X<$T0>*, X<int>*)#1}::operator()<char>(X<char>*,
 
 _ZZN1XIiE1FEvENKUliE_clEi
 X<int>::F()::{lambda(int)#1}::operator()(int) const
+
+_Z1fIiEv1AIXnxtlT_EEE
+void f<int>(A<noexcept(int{})>)