diff mbox series

[1/3] Remove const char * support for asm constexpr

Message ID 20240612172031.3827584-1-ak@linux.intel.com
State New
Headers show
Series [1/3] Remove const char * support for asm constexpr | expand

Commit Message

Andi Kleen June 12, 2024, 5:20 p.m. UTC
asm constexpr now only accepts the same string types as C++26 assert,
e.g. string_view and string. Adjust test suite and documentation.

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(-)

Comments

Jason Merrill June 13, 2024, 3:28 a.m. UTC | #1
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";
>   }
diff mbox series

Patch

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";
 }