public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/3] Remove const char * support for asm constexpr
@ 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
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andi Kleen @ 2024-06-12 17:20 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Andi Kleen

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

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


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

* [PATCH 2/3] Parse close paren even when constexpr extraction fails
  2024-06-12 17:20 [PATCH 1/3] Remove const char * support for asm constexpr Andi Kleen
@ 2024-06-12 17:20 ` Andi Kleen
  2024-06-12 17:20 ` [PATCH 3/3] Fix error message Andi Kleen
  2024-06-13  3:28 ` [PATCH 1/3] Remove const char * support for asm constexpr Jason Merrill
  2 siblings, 0 replies; 4+ messages in thread
From: Andi Kleen @ 2024-06-12 17:20 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Andi Kleen

To get better error recovery.

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_asm_string_expression): Parse close
	parent when constexpr extraction fails.
---
 gcc/cp/parser.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 98e8ca10ac40..adc4e6fc1aee 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -22856,7 +22856,7 @@ cp_parser_asm_string_expression (cp_parser *parser)
       if (!cstr.type_check (tok->location))
 	return error_mark_node;
       if (!cstr.extract (tok->location, string))
-	return error_mark_node;
+	string = error_mark_node;
       parens.require_close (parser);
       return string;
     }
-- 
2.45.1


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

* [PATCH 3/3] Fix error message
  2024-06-12 17:20 [PATCH 1/3] Remove const char * support for asm constexpr 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 ` Andi Kleen
  2024-06-13  3:28 ` [PATCH 1/3] Remove const char * support for asm constexpr Jason Merrill
  2 siblings, 0 replies; 4+ messages in thread
From: Andi Kleen @ 2024-06-12 17:20 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Andi Kleen

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_asm_string_expression): Use correct error
	message.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1z/constexpr-asm-3.C: Adjust for new message.
---
 gcc/cp/parser.cc                             | 2 +-
 gcc/testsuite/g++.dg/cpp1z/constexpr-asm-3.C | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index adc4e6fc1aee..01a19080d6c7 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -22863,7 +22863,7 @@ cp_parser_asm_string_expression (cp_parser *parser)
   else if (!cp_parser_is_string_literal (tok))
     {
       error_at (tok->location,
-		"expected string-literal or constexpr in brackets");
+		"expected string-literal or constexpr in parentheses");
       return error_mark_node;
     }
   return cp_parser_string_literal (parser, false, false);
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-3.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-3.C
index ef8a35a0b3ba..0cf8940e109c 100644
--- a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-3.C
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-3.C
@@ -26,7 +26,7 @@ constexpr std::string_view genclobber ()
 void f()
 {
   int a;
-  asm(genfoo () : /* { dg-error "expected string-literal or constexpr in brackets" } */
+  asm(genfoo () : /* { dg-error "expected string-literal or constexpr in parentheses" } */
       genoutput() (a) :
       geninput() (1) :
       genclobber());
-- 
2.45.1


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

* Re: [PATCH 1/3] Remove const char * support for asm constexpr
  2024-06-12 17:20 [PATCH 1/3] Remove const char * support for asm constexpr 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
  2 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2024-06-13  3:28 UTC (permalink / raw)
  To: Andi Kleen, gcc-patches

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


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

end of thread, other threads:[~2024-06-13  3:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-12 17:20 [PATCH 1/3] Remove const char * support for asm constexpr 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 ` [PATCH 1/3] Remove const char * support for asm constexpr 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).