public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: mangle noexcept-expr [PR70790]
@ 2023-05-19 18:38 Patrick Palka
  2023-05-19 19:10 ` Patrick Palka
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Palka @ 2023-05-19 18:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, nathan, Patrick Palka

This implements noexcept-expr mangling (and demangling) as per the
Itanium ABI.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this
look OK for trunk?

	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.
	* testsuite/demangle-expected: Test noexcept operator
	demangling.

gcc/testsuite/ChangeLog:

	* g++.dg/abi/mangle78.C: New test.
---
 gcc/cp/mangle.cc                      |  5 +++++
 gcc/testsuite/g++.dg/abi/mangle78.C   | 14 ++++++++++++++
 libiberty/cp-demangle.c               |  1 +
 libiberty/testsuite/demangle-expected |  3 +++
 4 files changed, 23 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/abi/mangle78.C

diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc
index 826c5e76c1d..7dab4e62bc9 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 00000000000..a3647711604
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/mangle78.C
@@ -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 "_Z1fIiEv1AIXnxcvT__EEE" } }
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index f2b36bcad68..341c66db919 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 },
diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
index d9bc7ed4b1f..7195cc39c19 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -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
+
+_Z1fIiEv1AIXnxcvT__EEE
+void f<int>(A<noexcept((int)())>)
-- 
2.41.0.rc0.4.g004e0f790f


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] c++: mangle noexcept-expr [PR70790]
  2023-05-19 18:38 [PATCH] c++: mangle noexcept-expr [PR70790] Patrick Palka
@ 2023-05-19 19:10 ` Patrick Palka
  2023-05-28 20:38   ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Palka @ 2023-05-19 19:10 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches, jason, nathan

On Fri, 19 May 2023, Patrick Palka wrote:

> This implements noexcept-expr mangling (and demangling) as per the
> Itanium ABI.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this
> look OK for trunk?
> 
> 	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.

Oops, we should also make sure we print parens around the operand of
noexcept.  Otherwise we'd demangle the mangling of e.g.

  void f<int>(A<noexcept(int{})>)

instead as

  void f<int>(A<noexceptint{}>)

Fixed in the following patch:

-- >8 --

Subject: [PATCH] c++: mangle noexcept-expr [PR70790]

This implements noexcept-expr mangling (and demangling) as per the
Itanium ABI.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this
look OK for trunk?

	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                      |  5 +++++
 gcc/testsuite/g++.dg/abi/mangle78.C   | 14 ++++++++++++++
 libiberty/cp-demangle.c               |  5 +++--
 libiberty/testsuite/demangle-expected |  3 +++
 4 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/abi/mangle78.C

diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc
index 826c5e76c1d..7dab4e62bc9 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 00000000000..63c4d779e9f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/mangle78.C
@@ -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" } }
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index f2b36bcad68..efada1c322b 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) or 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 d9bc7ed4b1f..52dff883a18 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -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{})>)
-- 
2.41.0.rc0.4.g004e0f790f

> 	* testsuite/demangle-expected: Test noexcept operator
> 	demangling.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/abi/mangle78.C: New test.
> ---
>  gcc/cp/mangle.cc                      |  5 +++++
>  gcc/testsuite/g++.dg/abi/mangle78.C   | 14 ++++++++++++++
>  libiberty/cp-demangle.c               |  1 +
>  libiberty/testsuite/demangle-expected |  3 +++
>  4 files changed, 23 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/abi/mangle78.C
> 
> diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc
> index 826c5e76c1d..7dab4e62bc9 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 00000000000..a3647711604
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/abi/mangle78.C
> @@ -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 "_Z1fIiEv1AIXnxcvT__EEE" } }
> diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
> index f2b36bcad68..341c66db919 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 },
> diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
> index d9bc7ed4b1f..7195cc39c19 100644
> --- a/libiberty/testsuite/demangle-expected
> +++ b/libiberty/testsuite/demangle-expected
> @@ -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
> +
> +_Z1fIiEv1AIXnxcvT__EEE
> +void f<int>(A<noexcept((int)())>)
> -- 
> 2.41.0.rc0.4.g004e0f790f
> 
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] c++: mangle noexcept-expr [PR70790]
  2023-05-19 19:10 ` Patrick Palka
@ 2023-05-28 20:38   ` Jason Merrill
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2023-05-28 20:38 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches, nathan

On 5/19/23 15:10, Patrick Palka wrote:
> On Fri, 19 May 2023, Patrick Palka wrote:
> 
>> This implements noexcept-expr mangling (and demangling) as per the
>> Itanium ABI.
>>
>> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this
>> look OK for trunk?
>>
>> 	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.
> 
> Oops, we should also make sure we print parens around the operand of
> noexcept.  Otherwise we'd demangle the mangling of e.g.
> 
>    void f<int>(A<noexcept(int{})>)
> 
> instead as
> 
>    void f<int>(A<noexceptint{}>)
> 
> Fixed in the following patch:
> 
> -- >8 --
> 
> Subject: [PATCH] c++: mangle noexcept-expr [PR70790]
> 
> This implements noexcept-expr mangling (and demangling) as per the
> Itanium ABI.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this
> look OK for trunk?

OK.  Incidentally, this paragraph should go before the scissors line 
since we don't want it to be part of the git commit comment.

> 	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                      |  5 +++++
>   gcc/testsuite/g++.dg/abi/mangle78.C   | 14 ++++++++++++++
>   libiberty/cp-demangle.c               |  5 +++--
>   libiberty/testsuite/demangle-expected |  3 +++
>   4 files changed, 25 insertions(+), 2 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/abi/mangle78.C
> 
> diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc
> index 826c5e76c1d..7dab4e62bc9 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 00000000000..63c4d779e9f
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/abi/mangle78.C
> @@ -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" } }
> diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
> index f2b36bcad68..efada1c322b 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) or 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 d9bc7ed4b1f..52dff883a18 100644
> --- a/libiberty/testsuite/demangle-expected
> +++ b/libiberty/testsuite/demangle-expected
> @@ -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{})>)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-28 20:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-19 18:38 [PATCH] c++: mangle noexcept-expr [PR70790] Patrick Palka
2023-05-19 19:10 ` Patrick Palka
2023-05-28 20:38   ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).