From: Patrick Palka Date: Sat, 3 Jun 2023 13:03:27 +0000 (-0400) Subject: c++: mangle noexcept-expr [PR70790] X-Git-Tag: basepoints/gcc-15~8623 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=999e617d3121b82921c8031ee695fd036f553f04;p=thirdparty%2Fgcc.git c++: mangle noexcept-expr [PR70790] 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) : 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. --- diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc index 826c5e76c1df..7dab4e62bc9e 100644 --- a/gcc/cp/mangle.cc +++ b/gcc/cp/mangle.cc @@ -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 index 000000000000..63c4d779e9f1 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/mangle78.C @@ -0,0 +1,14 @@ +// PR c++/70790 +// { dg-do compile { target c++11 } } + +template +struct A { }; + +template +void f(A); + +int main() { + f({}); +} + +// { dg-final { scan-assembler "_Z1fIiEv1AIXnxtlT_EEE" } } diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index f2b36bcad68b..18ab28fd028d 100644 --- a/libiberty/cp-demangle.c +++ b/libiberty/cp-demangle.c @@ -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); diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected index d9bc7ed4b1fc..52dff883a184 100644 --- a/libiberty/testsuite/demangle-expected +++ b/libiberty/testsuite/demangle-expected @@ -1659,3 +1659,6 @@ auto f()::{lambda(X<$T0>*, X*)#1}::operator()(X*, _ZZN1XIiE1FEvENKUliE_clEi X::F()::{lambda(int)#1}::operator()(int) const + +_Z1fIiEv1AIXnxtlT_EEE +void f(A)