public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Fix up __builtin_{bit_cast,convertvector} parsing
@ 2022-03-25 15:58 Jakub Jelinek
  2022-03-25 18:50 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2022-03-25 15:58 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

Jonathan reported on IRC that we don't parse
__builtin_bit_cast (type, val).field
etc.
The problem is that for these 2 builtins we return from
cp_parser_postfix_expression instead of setting postfix_expression
to the cp_build_* value and falling through into the postfix regression
suffix handling loop.

Ok for trunk if it passes bootstrap/regtest?

2022-03-25  Jakub Jelinek  <jakub@redhat.com>

	* parser.cc (cp_parser_postfix_expression)
	<case RID_BILTIN_CONVERTVECTOR, case RID_BUILTIN_BIT_CAST>: Don't
	return cp_build_{vec,convert,bit_cast} result right away, instead
	set postfix_expression to it and break.

	* c-c++-common/builtin-convertvector-3.c: New test.
	* g++.dg/cpp2a/bit-cast15.C: New test.

--- gcc/cp/parser.cc.jj	2022-03-15 09:15:21.366108714 +0100
+++ gcc/cp/parser.cc	2022-03-25 16:04:21.464248103 +0100
@@ -7525,8 +7525,10 @@ cp_parser_postfix_expression (cp_parser
 	}
 	/* Look for the closing `)'.  */
 	parens.require_close (parser);
-	return cp_build_vec_convert (expression, type_location, type,
-				     tf_warning_or_error);
+	postfix_expression
+	  = cp_build_vec_convert (expression, type_location, type,
+				  tf_warning_or_error);
+	break;
       }
 
     case RID_BUILTIN_BIT_CAST:
@@ -7551,8 +7553,10 @@ cp_parser_postfix_expression (cp_parser
 	expression = cp_parser_assignment_expression (parser);
 	/* Look for the closing `)'.  */
 	parens.require_close (parser);
-	return cp_build_bit_cast (type_location, type, expression,
-				  tf_warning_or_error);
+	postfix_expression
+	  = cp_build_bit_cast (type_location, type, expression,
+			       tf_warning_or_error);
+	break;
       }
 
     default:
--- gcc/testsuite/c-c++-common/builtin-convertvector-3.c.jj	2022-03-25 16:23:18.033120090 +0100
+++ gcc/testsuite/c-c++-common/builtin-convertvector-3.c	2022-03-25 16:23:40.633799410 +0100
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+typedef int v4si __attribute__((vector_size (4 * sizeof (int))));
+typedef double v4df __attribute__((vector_size (4 * sizeof (double))));
+double
+foo (void)
+{
+  v4si a = { 1, 2, 3, 4 };
+  return __builtin_convertvector (a, v4df)[1];
+}
--- gcc/testsuite/g++.dg/cpp2a/bit-cast15.C.jj	2022-03-25 16:26:22.271505979 +0100
+++ gcc/testsuite/g++.dg/cpp2a/bit-cast15.C	2022-03-25 16:26:15.907596274 +0100
@@ -0,0 +1,19 @@
+// { dg-do compile }
+
+struct S { short a, b; };
+struct T { float a[4]; };
+struct U { int b[4]; };
+
+#if __SIZEOF_FLOAT__ == __SIZEOF_INT__
+int
+f1 (T &x)
+{
+  return __builtin_bit_cast (U, x).b[1];
+}
+
+float
+f2 (int (&x)[4])
+{
+  return __builtin_bit_cast (T, x).a[2];
+}
+#endif

	Jakub


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

* Re: [PATCH] c++: Fix up __builtin_{bit_cast,convertvector} parsing
  2022-03-25 15:58 [PATCH] c++: Fix up __builtin_{bit_cast,convertvector} parsing Jakub Jelinek
@ 2022-03-25 18:50 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-03-25 18:50 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On 3/25/22 11:58, Jakub Jelinek wrote:
> Hi!
> 
> Jonathan reported on IRC that we don't parse
> __builtin_bit_cast (type, val).field
> etc.
> The problem is that for these 2 builtins we return from
> cp_parser_postfix_expression instead of setting postfix_expression
> to the cp_build_* value and falling through into the postfix regression
> suffix handling loop.
> 
> Ok for trunk if it passes bootstrap/regtest?

OK.

> 2022-03-25  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* parser.cc (cp_parser_postfix_expression)
> 	<case RID_BILTIN_CONVERTVECTOR, case RID_BUILTIN_BIT_CAST>: Don't
> 	return cp_build_{vec,convert,bit_cast} result right away, instead
> 	set postfix_expression to it and break.
> 
> 	* c-c++-common/builtin-convertvector-3.c: New test.
> 	* g++.dg/cpp2a/bit-cast15.C: New test.
> 
> --- gcc/cp/parser.cc.jj	2022-03-15 09:15:21.366108714 +0100
> +++ gcc/cp/parser.cc	2022-03-25 16:04:21.464248103 +0100
> @@ -7525,8 +7525,10 @@ cp_parser_postfix_expression (cp_parser
>   	}
>   	/* Look for the closing `)'.  */
>   	parens.require_close (parser);
> -	return cp_build_vec_convert (expression, type_location, type,
> -				     tf_warning_or_error);
> +	postfix_expression
> +	  = cp_build_vec_convert (expression, type_location, type,
> +				  tf_warning_or_error);
> +	break;
>         }
>   
>       case RID_BUILTIN_BIT_CAST:
> @@ -7551,8 +7553,10 @@ cp_parser_postfix_expression (cp_parser
>   	expression = cp_parser_assignment_expression (parser);
>   	/* Look for the closing `)'.  */
>   	parens.require_close (parser);
> -	return cp_build_bit_cast (type_location, type, expression,
> -				  tf_warning_or_error);
> +	postfix_expression
> +	  = cp_build_bit_cast (type_location, type, expression,
> +			       tf_warning_or_error);
> +	break;
>         }
>   
>       default:
> --- gcc/testsuite/c-c++-common/builtin-convertvector-3.c.jj	2022-03-25 16:23:18.033120090 +0100
> +++ gcc/testsuite/c-c++-common/builtin-convertvector-3.c	2022-03-25 16:23:40.633799410 +0100
> @@ -0,0 +1,11 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2" } */
> +
> +typedef int v4si __attribute__((vector_size (4 * sizeof (int))));
> +typedef double v4df __attribute__((vector_size (4 * sizeof (double))));
> +double
> +foo (void)
> +{
> +  v4si a = { 1, 2, 3, 4 };
> +  return __builtin_convertvector (a, v4df)[1];
> +}
> --- gcc/testsuite/g++.dg/cpp2a/bit-cast15.C.jj	2022-03-25 16:26:22.271505979 +0100
> +++ gcc/testsuite/g++.dg/cpp2a/bit-cast15.C	2022-03-25 16:26:15.907596274 +0100
> @@ -0,0 +1,19 @@
> +// { dg-do compile }
> +
> +struct S { short a, b; };
> +struct T { float a[4]; };
> +struct U { int b[4]; };
> +
> +#if __SIZEOF_FLOAT__ == __SIZEOF_INT__
> +int
> +f1 (T &x)
> +{
> +  return __builtin_bit_cast (U, x).b[1];
> +}
> +
> +float
> +f2 (int (&x)[4])
> +{
> +  return __builtin_bit_cast (T, x).a[2];
> +}
> +#endif
> 
> 	Jakub
> 


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

end of thread, other threads:[~2022-03-25 18:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-25 15:58 [PATCH] c++: Fix up __builtin_{bit_cast,convertvector} parsing Jakub Jelinek
2022-03-25 18:50 ` 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).