public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: Adjust mangling of __alignof__ [PR88115]
Date: Tue, 30 Mar 2021 16:56:33 -0400	[thread overview]
Message-ID: <cdcfb2c1-456b-46d9-f6e3-ef020207d95e@redhat.com> (raw)
In-Reply-To: <20210330191702.4147705-1-ppalka@redhat.com>

On 3/30/21 3:17 PM, Patrick Palka wrote:
> We currently mangle __alignof__ as a vendor extended operator,
> but that's problematic for the reasons mentioned in
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88115#c6.
> 
> This patch changes the mangling of __alignof__ to instead use the
> new "vendor extended expression" syntax that's proposed in
> https://github.com/itanium-cxx-abi/cxx-abi/issues/112.  Clang does
> the same thing already, so after this patch both GCC and Clang agree
> about the mangling of __alignof__(type) and __alignof__(expr).
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?

OK.

> gcc/cp/ChangeLog:
> 
> 	PR c++/88115
> 	* mangle.c (write_expression): Adjust the mangling of
> 	__alignof__.
> 
> include/ChangeLog:
> 
> 	PR c++/88115
> 	* demangle.h (enum demangle_component_type): Add
> 	DEMANGLE_COMPONENT_VENDOR_EXPR.
> 
> libiberty/ChangeLog:
> 
> 	PR c++/88115
> 	* cp-demangle.c (d_dump, d_make_comp, d_expression_1)
> 	(d_count_templates_scopes): Handle DEMANGLE_COMPONENT_VENDOR_EXPR.
> 	(d_print_comp_inner): Likewise.
> 	<case DEMANGLE_COMPONENT_EXTENDED_OPERATOR>: Revert r11-4926
> 	change.
> 	<case DEMANGLE_COMPONENT_UNARY>: Likewise.
> 	* testsuite/demangle-expected: Adjust __alignof__ mangling
> 	tests.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR c++/88115
> 	* g++.dg/cpp0x/alignof7.C: Adjust expected mangling.
> ---
>   gcc/cp/mangle.c                       |  8 ++---
>   gcc/testsuite/g++.dg/cpp0x/alignof7.C |  4 +--
>   include/demangle.h                    |  3 ++
>   libiberty/cp-demangle.c               | 47 +++++++++++++++------------
>   libiberty/testsuite/demangle-expected |  4 +--
>   5 files changed, 37 insertions(+), 29 deletions(-)
> 
> diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
> index 0a9e5aa79a0..57ce9a6710f 100644
> --- a/gcc/cp/mangle.c
> +++ b/gcc/cp/mangle.c
> @@ -3124,11 +3124,9 @@ write_expression (tree expr)
>   	  if (abi_version_at_least (15))
>   	    {
>   	      /* We used to mangle __alignof__ like alignof.  */
> -	      write_string ("v111__alignof__");
> -	      if (TYPE_P (TREE_OPERAND (expr, 0)))
> -		write_type (TREE_OPERAND (expr, 0));
> -	      else
> -		write_expression (TREE_OPERAND (expr, 0));
> +	      write_string ("u11__alignof__");
> +	      write_template_arg (TREE_OPERAND (expr, 0));
> +	      write_char ('E');
>   	      return;
>   	    }
>   	}
> diff --git a/gcc/testsuite/g++.dg/cpp0x/alignof7.C b/gcc/testsuite/g++.dg/cpp0x/alignof7.C
> index a4d7f24a4d7..2369b879392 100644
> --- a/gcc/testsuite/g++.dg/cpp0x/alignof7.C
> +++ b/gcc/testsuite/g++.dg/cpp0x/alignof7.C
> @@ -18,5 +18,5 @@ template void f4<int>(std::size_t);
>   
>   // { dg-final { scan-assembler "_Z2f1IiEvDTatT_E" } }
>   // { dg-final { scan-assembler "_Z2f2IiEvDTaztlT_EE" } }
> -// { dg-final { scan-assembler "_Z2f3IiEvDTv111__alignof__T_E" } }
> -// { dg-final { scan-assembler "_Z2f4IiEvDTv111__alignof__tlT_EE" } }
> +// { dg-final { scan-assembler "_Z2f3IiEvDTu11__alignof__T_EE" } }
> +// { dg-final { scan-assembler "_Z2f4IiEvDTu11__alignof__XtlT_EEEE" } }
> diff --git a/include/demangle.h b/include/demangle.h
> index 23b47265d94..b45234e6887 100644
> --- a/include/demangle.h
> +++ b/include/demangle.h
> @@ -408,6 +408,9 @@ enum demangle_component_type
>        number which involves neither modifying the mangled string nor
>        allocating a new copy of the literal in memory.  */
>     DEMANGLE_COMPONENT_LITERAL_NEG,
> +  /* A vendor's builtin expression.  The left subtree holds the name of
> +     the type, and the right subtree is a template argument list.  */
> +  DEMANGLE_COMPONENT_VENDOR_EXPR,
>     /* A libgcj compiled resource.  The left subtree is the name of the
>        resource.  */
>     DEMANGLE_COMPONENT_JAVA_RESOURCE,
> diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
> index d3e798455cc..a528b7b5ed3 100644
> --- a/libiberty/cp-demangle.c
> +++ b/libiberty/cp-demangle.c
> @@ -815,6 +815,9 @@ d_dump (struct demangle_component *dc, int indent)
>       case DEMANGLE_COMPONENT_LITERAL_NEG:
>         printf ("negative literal\n");
>         break;
> +    case DEMANGLE_COMPONENT_VENDOR_EXPR:
> +      printf ("vendor expression\n");
> +      break;
>       case DEMANGLE_COMPONENT_JAVA_RESOURCE:
>         printf ("java resource\n");
>         break;
> @@ -976,6 +979,7 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
>       case DEMANGLE_COMPONENT_TRINARY_ARG1:
>       case DEMANGLE_COMPONENT_LITERAL:
>       case DEMANGLE_COMPONENT_LITERAL_NEG:
> +    case DEMANGLE_COMPONENT_VENDOR_EXPR:
>       case DEMANGLE_COMPONENT_COMPOUND_NAME:
>       case DEMANGLE_COMPONENT_VECTOR_TYPE:
>       case DEMANGLE_COMPONENT_CLONE:
> @@ -3345,6 +3349,7 @@ d_unresolved_name (struct d_info *di)
>                   ::= st <type>
>                   ::= <template-param>
>   		::= <unresolved-name>
> +		::= u <source-name> <template-arg>* E # vendor extended expression
>                   ::= <expr-primary>
>   
>     <braced-expression> ::= <expression>
> @@ -3425,6 +3430,15 @@ d_expression_1 (struct d_info *di)
>         return d_make_comp (di, DEMANGLE_COMPONENT_INITIALIZER_LIST,
>   			  type, d_exprlist (di, 'E'));
>       }
> +  else if (peek == 'u')
> +    {
> +      /* A vendor extended expression.  */
> +      struct demangle_component *name, *args;
> +      d_advance (di, 1);
> +      name = d_source_name (di);
> +      args = d_template_args_1 (di);
> +      return d_make_comp (di, DEMANGLE_COMPONENT_VENDOR_EXPR, name, args);
> +    }
>     else
>       {
>         struct demangle_component *op;
> @@ -4229,6 +4243,7 @@ d_count_templates_scopes (struct d_print_info *dpi,
>       case DEMANGLE_COMPONENT_TRINARY_ARG2:
>       case DEMANGLE_COMPONENT_LITERAL:
>       case DEMANGLE_COMPONENT_LITERAL_NEG:
> +    case DEMANGLE_COMPONENT_VENDOR_EXPR:
>       case DEMANGLE_COMPONENT_JAVA_RESOURCE:
>       case DEMANGLE_COMPONENT_COMPOUND_NAME:
>       case DEMANGLE_COMPONENT_DECLTYPE:
> @@ -5509,18 +5524,9 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
>         }
>   
>       case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
> -      {
> -	struct demangle_component *name = dc->u.s_extended_operator.name;
> -	if (name->type == DEMANGLE_COMPONENT_NAME
> -	    && !strncmp (name->u.s_name.s, "__alignof__", name->u.s_name.len))
> -	  d_print_comp (dpi, options, dc->u.s_extended_operator.name);
> -	else
> -	  {
> -	    d_append_string (dpi, "operator ");
> -	    d_print_comp (dpi, options, dc->u.s_extended_operator.name);
> -	  }
> -	return;
> -      }
> +      d_append_string (dpi, "operator ");
> +      d_print_comp (dpi, options, dc->u.s_extended_operator.name);
> +      return;
>   
>       case DEMANGLE_COMPONENT_CONVERSION:
>         d_append_string (dpi, "operator ");
> @@ -5585,14 +5591,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"))
> -		 || (op->type == DEMANGLE_COMPONENT_EXTENDED_OPERATOR
> -		     && (op->u.s_extended_operator.name->type
> -			 == DEMANGLE_COMPONENT_NAME)
> -		     && !strncmp (op->u.s_extended_operator.name->u.s_name.s,
> -				  "__alignof__",
> -				  op->u.s_extended_operator.name->u.s_name.len)))
> -	  /* Always print parens for sizeof (type) and __alignof__.  */
> +	else if (code && !strcmp (code, "st"))
> +	  /* Always print parens for sizeof (type).  */
>   	  {
>   	    d_append_char (dpi, '(');
>   	    d_print_comp (dpi, options, operand);
> @@ -5805,6 +5805,13 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
>         }
>         return;
>   
> +    case DEMANGLE_COMPONENT_VENDOR_EXPR:
> +      d_print_comp (dpi, options, d_left (dc));
> +      d_append_char (dpi, '(');
> +      d_print_comp (dpi, options, d_right (dc));
> +      d_append_char (dpi, ')');
> +      return;
> +
>       case DEMANGLE_COMPONENT_NUMBER:
>         d_append_num (dpi, dc->u.s_number.number);
>         return;
> diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
> index e6b5b64b9a9..19a0d621bc0 100644
> --- a/libiberty/testsuite/demangle-expected
> +++ b/libiberty/testsuite/demangle-expected
> @@ -1471,10 +1471,10 @@ _Z2F2IZ1FvEUlvE_EN1AIT_E1XES2_
>   A<F()::{lambda()#1}>::X F2<F()::{lambda()#1}>(F()::{lambda()#1})
>   
>   # PR 88115
> -_Z1fIiEvDTv111__alignof__T_E
> +_Z1fIiEvDTu11__alignof__T_EE
>   void f<int>(decltype (__alignof__(int)))
>   
> -_Z1fIiEvDTv111__alignof__tlT_EE
> +_Z1fIiEvDTu11__alignof__XtlT_EEEE
>   void f<int>(decltype (__alignof__(int{})))
>   
>   _Z1gI1AEv1SIXadsrT_oncviEE
> 


      reply	other threads:[~2021-03-30 20:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30 19:17 Patrick Palka
2021-03-30 20:56 ` Jason Merrill [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cdcfb2c1-456b-46d9-f6e3-ef020207d95e@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).