public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Andi Kleen <ak@linux.intel.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 1/3] Remove const char * support for asm constexpr
Date: Wed, 12 Jun 2024 23:28:11 -0400	[thread overview]
Message-ID: <8bbff3dd-ed81-4019-abef-404385f5c455@redhat.com> (raw)
In-Reply-To: <20240612172031.3827584-1-ak@linux.intel.com>

On 6/12/24 13:20, Andi Kleen wrote:
> asm constexpr now only accepts the same string types as C++26 assert,
> e.g. string_view and string. Adjust test suite and documentation.

This patchset is all OK, thanks.

> gcc/cp/ChangeLog:
> 
> 	* parser.cc (cp_parser_asm_string_expression): Remove support
> 	  for const char * for asm constexpr.
> 
> gcc/ChangeLog:
> 
> 	* doc/extend.texi: Use std::string_view in asm constexpr
> 	example.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp1z/constexpr-asm-1.C: Use std::std_string_view.
> 	* g++.dg/cpp1z/constexpr-asm-3.C: Dito.
> ---
>   gcc/cp/parser.cc                             |  7 -------
>   gcc/doc/extend.texi                          |  3 ++-
>   gcc/testsuite/g++.dg/cpp1z/constexpr-asm-1.C | 12 +++++++-----
>   gcc/testsuite/g++.dg/cpp1z/constexpr-asm-3.C | 12 +++++++-----
>   4 files changed, 16 insertions(+), 18 deletions(-)
> 
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index de5f0483c120..98e8ca10ac40 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -22852,13 +22852,6 @@ cp_parser_asm_string_expression (cp_parser *parser)
>         tree string = cp_parser_constant_expression (parser);
>         if (string != error_mark_node)
>   	string = cxx_constant_value (string, tf_error);
> -      if (TREE_CODE (string) == NOP_EXPR)
> -	string = TREE_OPERAND (string, 0);
> -      if (TREE_CODE (string) == ADDR_EXPR
> -	  && TREE_CODE (TREE_OPERAND (string, 0)) == STRING_CST)
> -	string = TREE_OPERAND (string, 0);
> -      if (TREE_CODE (string) == VIEW_CONVERT_EXPR)
> -	string = TREE_OPERAND (string, 0);
>         cexpr_str cstr (string);
>         if (!cstr.type_check (tok->location))
>   	return error_mark_node;
> diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
> index 17e26c5004c1..ee3644a52645 100644
> --- a/gcc/doc/extend.texi
> +++ b/gcc/doc/extend.texi
> @@ -10716,7 +10716,8 @@ message. Any string is converted to the character set of the source code.
>   When this feature is available the @code{__GXX_CONSTEXPR_ASM__} cpp symbol is defined.
>   
>   @example
> -constexpr const char *genfoo() @{ return "foo"; @}
> +#include <string>
> +constexpr std::string_view genfoo() @{ return "foo"; @}
>   
>   void function()
>   @{
> diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-1.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-1.C
> index 7cc6b37d6208..311209acb43b 100644
> --- a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-1.C
> +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-1.C
> @@ -1,22 +1,24 @@
>   /* { dg-do compile } */
> -/* { dg-options "-std=gnu++11" } */
> +/* { dg-options "-std=gnu++17" } */
>   
> -constexpr const char *genfoo ()
> +#include <string>
> +
> +constexpr std::string_view genfoo ()
>   {
>     return "foo %1,%0";
>   }
>   
> -constexpr const char *genoutput ()
> +constexpr std::string_view genoutput ()
>   {
>     return "=r";
>   }
>   
> -constexpr const char *geninput ()
> +constexpr std::string_view geninput ()
>   {
>     return "r";
>   }
>   
> -constexpr const char *genclobber ()
> +constexpr std::string_view genclobber ()
>   {
>     return "memory";
>   }
> diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-3.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-3.C
> index d33631876bdc..ef8a35a0b3ba 100644
> --- a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-3.C
> +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-3.C
> @@ -1,22 +1,24 @@
>   /* { dg-do compile } */
> -/* { dg-options "-std=gnu++11" } */
> +/* { dg-options "-std=gnu++17" } */
>   
> -constexpr const char *genfoo ()
> +#include <string>
> +
> +constexpr std::string_view genfoo ()
>   {
>     return "foo %1,%0";
>   }
>   
> -constexpr const char *genoutput ()
> +constexpr std::string_view genoutput ()
>   {
>     return "=r";
>   }
>   
> -constexpr const char *geninput ()
> +constexpr std::string_view geninput ()
>   {
>     return "r";
>   }
>   
> -constexpr const char *genclobber ()
> +constexpr std::string_view genclobber ()
>   {
>     return "memory";
>   }


      parent reply	other threads:[~2024-06-13  3:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-12 17:20 Andi Kleen
2024-06-12 17:20 ` [PATCH 2/3] Parse close paren even when constexpr extraction fails Andi Kleen
2024-06-12 17:20 ` [PATCH 3/3] Fix error message Andi Kleen
2024-06-13  3:28 ` 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=8bbff3dd-ed81-4019-abef-404385f5c455@redhat.com \
    --to=jason@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).