public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: __builtin_shufflevector with value-dep expr [PR105353]
@ 2022-04-22 23:57 Marek Polacek
  2022-04-23  6:25 ` Richard Biener
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Marek Polacek @ 2022-04-22 23:57 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill; +Cc: Richard Biener

Here we issue an error from c_build_shufflevector while parsing a template
because it got a TEMPLATE_PARM_INDEX, but this function expects INTEGER_CSTs
(except the first two arguments).  It checks if any of the arguments are
type-dependent, if so, we leave the processing for later, but it should
also check value-dependency for the 3rd+ arguments, so as to avoid the
problem above.

This is not a regression -- __builtin_shufflevector was introduced in
GCC 12, but it looks safe enough.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

	PR c++/105353

gcc/cp/ChangeLog:

	* typeck.cc (build_x_shufflevector): Use
	instantiation_dependent_expression_p except for the first two
	arguments.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/builtin-shufflevector-3.C: New test.
---
 gcc/cp/typeck.cc                              |  4 +++-
 .../g++.dg/ext/builtin-shufflevector-3.C      | 23 +++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C

diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 26a7cb4b50d..0da6f2485d0 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -6315,7 +6315,9 @@ build_x_shufflevector (location_t loc, vec<tree, va_gc> *args,
   if (processing_template_decl)
     {
       for (unsigned i = 0; i < args->length (); ++i)
-	if (type_dependent_expression_p ((*args)[i]))
+	if (i <= 1
+	    ? type_dependent_expression_p ((*args)[i])
+	    : instantiation_dependent_expression_p ((*args)[i]))
 	  {
 	    tree exp = build_min_nt_call_vec (NULL, args);
 	    CALL_EXPR_IFN (exp) = IFN_SHUFFLEVECTOR;
diff --git a/gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C b/gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C
new file mode 100644
index 00000000000..0f3cbbee563
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C
@@ -0,0 +1,23 @@
+// PR c++/105353
+// { dg-do compile { target c++17 } }
+// { dg-additional-options "-Wno-psabi" }
+
+typedef unsigned char Simd128U8VectT __attribute__((__vector_size__(16)));
+
+template<int ShuffleIndex>
+static inline Simd128U8VectT ShufFunc(Simd128U8VectT vect) noexcept {
+    if constexpr(unsigned(ShuffleIndex) >= 16)
+        return Simd128U8VectT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+    else if constexpr(ShuffleIndex == 0)
+        return vect;
+    else
+        return __builtin_shufflevector(vect, vect, ShuffleIndex, ShuffleIndex + 1,
+            ShuffleIndex + 2, ShuffleIndex + 3, ShuffleIndex + 4, ShuffleIndex + 5,
+            ShuffleIndex + 6, ShuffleIndex + 7, ShuffleIndex + 8, ShuffleIndex + 9,
+            ShuffleIndex + 10, ShuffleIndex + 11, ShuffleIndex + 12, ShuffleIndex + 13,
+            ShuffleIndex + 14, ShuffleIndex + 15);
+}
+
+auto func1(Simd128U8VectT vect) noexcept {
+    return ShufFunc<5>(vect);
+}

base-commit: 7c21556daf385fe9ece37319f574776dd7d8ab1c
-- 
2.35.1


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

* Re: [PATCH] c++: __builtin_shufflevector with value-dep expr [PR105353]
  2022-04-22 23:57 [PATCH] c++: __builtin_shufflevector with value-dep expr [PR105353] Marek Polacek
@ 2022-04-23  6:25 ` Richard Biener
  2022-04-23  6:54 ` Jakub Jelinek
  2022-04-25 15:14 ` Jason Merrill
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2022-04-23  6:25 UTC (permalink / raw)
  To: Marek Polacek via Gcc-patches



> Am 23.04.2022 um 01:58 schrieb Marek Polacek via Gcc-patches <gcc-patches@gcc.gnu.org>:
> 
> Here we issue an error from c_build_shufflevector while parsing a template
> because it got a TEMPLATE_PARM_INDEX, but this function expects INTEGER_CSTs
> (except the first two arguments).  It checks if any of the arguments are
> type-dependent, if so, we leave the processing for later, but it should
> also check value-dependency for the 3rd+ arguments, so as to avoid the
> problem above.
> 
> This is not a regression -- __builtin_shufflevector was introduced in
> GCC 12, but it looks safe enough.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

Fine with me.

Richard 

>    PR c++/105353
> 
> gcc/cp/ChangeLog:
> 
>    * typeck.cc (build_x_shufflevector): Use
>    instantiation_dependent_expression_p except for the first two
>    arguments.
> 
> gcc/testsuite/ChangeLog:
> 
>    * g++.dg/ext/builtin-shufflevector-3.C: New test.
> ---
> gcc/cp/typeck.cc                              |  4 +++-
> .../g++.dg/ext/builtin-shufflevector-3.C      | 23 +++++++++++++++++++
> 2 files changed, 26 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C
> 
> diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
> index 26a7cb4b50d..0da6f2485d0 100644
> --- a/gcc/cp/typeck.cc
> +++ b/gcc/cp/typeck.cc
> @@ -6315,7 +6315,9 @@ build_x_shufflevector (location_t loc, vec<tree, va_gc> *args,
>   if (processing_template_decl)
>     {
>       for (unsigned i = 0; i < args->length (); ++i)
> -    if (type_dependent_expression_p ((*args)[i]))
> +    if (i <= 1
> +        ? type_dependent_expression_p ((*args)[i])
> +        : instantiation_dependent_expression_p ((*args)[i]))
>      {
>        tree exp = build_min_nt_call_vec (NULL, args);
>        CALL_EXPR_IFN (exp) = IFN_SHUFFLEVECTOR;
> diff --git a/gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C b/gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C
> new file mode 100644
> index 00000000000..0f3cbbee563
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C
> @@ -0,0 +1,23 @@
> +// PR c++/105353
> +// { dg-do compile { target c++17 } }
> +// { dg-additional-options "-Wno-psabi" }
> +
> +typedef unsigned char Simd128U8VectT __attribute__((__vector_size__(16)));
> +
> +template<int ShuffleIndex>
> +static inline Simd128U8VectT ShufFunc(Simd128U8VectT vect) noexcept {
> +    if constexpr(unsigned(ShuffleIndex) >= 16)
> +        return Simd128U8VectT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
> +    else if constexpr(ShuffleIndex == 0)
> +        return vect;
> +    else
> +        return __builtin_shufflevector(vect, vect, ShuffleIndex, ShuffleIndex + 1,
> +            ShuffleIndex + 2, ShuffleIndex + 3, ShuffleIndex + 4, ShuffleIndex + 5,
> +            ShuffleIndex + 6, ShuffleIndex + 7, ShuffleIndex + 8, ShuffleIndex + 9,
> +            ShuffleIndex + 10, ShuffleIndex + 11, ShuffleIndex + 12, ShuffleIndex + 13,
> +            ShuffleIndex + 14, ShuffleIndex + 15);
> +}
> +
> +auto func1(Simd128U8VectT vect) noexcept {
> +    return ShufFunc<5>(vect);
> +}
> 
> base-commit: 7c21556daf385fe9ece37319f574776dd7d8ab1c
> -- 
> 2.35.1
> 

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

* Re: [PATCH] c++: __builtin_shufflevector with value-dep expr [PR105353]
  2022-04-22 23:57 [PATCH] c++: __builtin_shufflevector with value-dep expr [PR105353] Marek Polacek
  2022-04-23  6:25 ` Richard Biener
@ 2022-04-23  6:54 ` Jakub Jelinek
  2022-04-25 15:14 ` Jason Merrill
  2 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2022-04-23  6:54 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches, Jason Merrill, Richard Biener

On Fri, Apr 22, 2022 at 07:57:34PM -0400, Marek Polacek via Gcc-patches wrote:
> Here we issue an error from c_build_shufflevector while parsing a template
> because it got a TEMPLATE_PARM_INDEX, but this function expects INTEGER_CSTs
> (except the first two arguments).  It checks if any of the arguments are
> type-dependent, if so, we leave the processing for later, but it should
> also check value-dependency for the 3rd+ arguments, so as to avoid the
> problem above.
> 
> This is not a regression -- __builtin_shufflevector was introduced in
> GCC 12, but it looks safe enough.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> 
> 	PR c++/105353
> 
> gcc/cp/ChangeLog:
> 
> 	* typeck.cc (build_x_shufflevector): Use
> 	instantiation_dependent_expression_p except for the first two
> 	arguments.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/ext/builtin-shufflevector-3.C: New test.

LGTM.

	Jakub


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

* Re: [PATCH] c++: __builtin_shufflevector with value-dep expr [PR105353]
  2022-04-22 23:57 [PATCH] c++: __builtin_shufflevector with value-dep expr [PR105353] Marek Polacek
  2022-04-23  6:25 ` Richard Biener
  2022-04-23  6:54 ` Jakub Jelinek
@ 2022-04-25 15:14 ` Jason Merrill
  2 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2022-04-25 15:14 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches; +Cc: Richard Biener

On 4/22/22 19:57, Marek Polacek wrote:
> Here we issue an error from c_build_shufflevector while parsing a template
> because it got a TEMPLATE_PARM_INDEX, but this function expects INTEGER_CSTs
> (except the first two arguments).  It checks if any of the arguments are
> type-dependent, if so, we leave the processing for later, but it should
> also check value-dependency for the 3rd+ arguments, so as to avoid the
> problem above.
> 
> This is not a regression -- __builtin_shufflevector was introduced in
> GCC 12, but it looks safe enough.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

OK.

> 	PR c++/105353
> 
> gcc/cp/ChangeLog:
> 
> 	* typeck.cc (build_x_shufflevector): Use
> 	instantiation_dependent_expression_p except for the first two
> 	arguments.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/ext/builtin-shufflevector-3.C: New test.
> ---
>   gcc/cp/typeck.cc                              |  4 +++-
>   .../g++.dg/ext/builtin-shufflevector-3.C      | 23 +++++++++++++++++++
>   2 files changed, 26 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C
> 
> diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
> index 26a7cb4b50d..0da6f2485d0 100644
> --- a/gcc/cp/typeck.cc
> +++ b/gcc/cp/typeck.cc
> @@ -6315,7 +6315,9 @@ build_x_shufflevector (location_t loc, vec<tree, va_gc> *args,
>     if (processing_template_decl)
>       {
>         for (unsigned i = 0; i < args->length (); ++i)
> -	if (type_dependent_expression_p ((*args)[i]))
> +	if (i <= 1
> +	    ? type_dependent_expression_p ((*args)[i])
> +	    : instantiation_dependent_expression_p ((*args)[i]))
>   	  {
>   	    tree exp = build_min_nt_call_vec (NULL, args);
>   	    CALL_EXPR_IFN (exp) = IFN_SHUFFLEVECTOR;
> diff --git a/gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C b/gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C
> new file mode 100644
> index 00000000000..0f3cbbee563
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C
> @@ -0,0 +1,23 @@
> +// PR c++/105353
> +// { dg-do compile { target c++17 } }
> +// { dg-additional-options "-Wno-psabi" }
> +
> +typedef unsigned char Simd128U8VectT __attribute__((__vector_size__(16)));
> +
> +template<int ShuffleIndex>
> +static inline Simd128U8VectT ShufFunc(Simd128U8VectT vect) noexcept {
> +    if constexpr(unsigned(ShuffleIndex) >= 16)
> +        return Simd128U8VectT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
> +    else if constexpr(ShuffleIndex == 0)
> +        return vect;
> +    else
> +        return __builtin_shufflevector(vect, vect, ShuffleIndex, ShuffleIndex + 1,
> +            ShuffleIndex + 2, ShuffleIndex + 3, ShuffleIndex + 4, ShuffleIndex + 5,
> +            ShuffleIndex + 6, ShuffleIndex + 7, ShuffleIndex + 8, ShuffleIndex + 9,
> +            ShuffleIndex + 10, ShuffleIndex + 11, ShuffleIndex + 12, ShuffleIndex + 13,
> +            ShuffleIndex + 14, ShuffleIndex + 15);
> +}
> +
> +auto func1(Simd128U8VectT vect) noexcept {
> +    return ShufFunc<5>(vect);
> +}
> 
> base-commit: 7c21556daf385fe9ece37319f574776dd7d8ab1c


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

end of thread, other threads:[~2022-04-25 15:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-22 23:57 [PATCH] c++: __builtin_shufflevector with value-dep expr [PR105353] Marek Polacek
2022-04-23  6:25 ` Richard Biener
2022-04-23  6:54 ` Jakub Jelinek
2022-04-25 15:14 ` 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).