public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Fix up vector cond expr handling in templates (PR c++/71871)
@ 2016-07-14 15:21 Jakub Jelinek
  2016-07-18 17:19 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2016-07-14 15:21 UTC (permalink / raw)
  To: Jason Merrill, Marc Glisse; +Cc: gcc-patches

Hi!

This patch reverts part of
https://gcc.gnu.org/ml/gcc-patches/2012-10/msg01665.html
which looks wrong to me.
The problem is that in templates, if the build_x_conditional_expr
arguments aren't type dependent, we might get NON_DEPENDENT_EXPR
wrappers around the argument, so after issuing possibly needed diagnostics
we need to return back to the original unmodified arguments,
which for VEC_COND_EXPR the condition has been bypassing and we ended up
with NON_DEPENDENT_EXPR in the IL, which nothing strips away
(plus VEC_COND_EXPR isn't really supported in tsubst_copy/tsubst_copy_and_build
and perhaps other spots).
While we could do build_min_non_dep with VEC_COND_EXPR and teach pt.c about
VEC_COND_EXPR, I really don't see advantages of doing that, if we build just
COND_EXPR, build_min_non_dep ensures that it will have the right type, and
when we instantiate it build_x_conditional_expr will be called again and
that will create VEC_COND_EXPR when not processing_template_decl.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-07-14  Jakub Jelinek  <jakub@redhat.com>

	PR c++/71871
	* typeck.c (build_x_conditional_expr): Revert the 2012-10-25 change.

	* g++.dg/ext/vector31.C: New test.

--- gcc/cp/typeck.c.jj	2016-07-11 11:14:28.000000000 +0200
+++ gcc/cp/typeck.c	2016-07-14 12:47:48.436699222 +0200
@@ -6288,8 +6288,7 @@ build_x_conditional_expr (location_t loc
     }
 
   expr = build_conditional_expr (loc, ifexp, op1, op2, complain);
-  if (processing_template_decl && expr != error_mark_node
-      && TREE_CODE (expr) != VEC_COND_EXPR)
+  if (processing_template_decl && expr != error_mark_node)
     {
       tree min = build_min_non_dep (COND_EXPR, expr,
 				    orig_ifexp, orig_op1, orig_op2);
--- gcc/testsuite/g++.dg/ext/vector31.C.jj	2016-07-14 13:01:04.933206583 +0200
+++ gcc/testsuite/g++.dg/ext/vector31.C	2016-07-14 13:00:59.943272143 +0200
@@ -0,0 +1,29 @@
+// PR c++/71871
+// { dg-do compile }
+
+typedef unsigned int V __attribute__ ((__vector_size__ (32)));
+
+template <int N>
+void
+foo (V *x)
+{
+  V a = *x;
+  a = a ? a : -1;
+  *x = a;
+}
+
+template <typename T>
+void
+bar (T *x)
+{
+  T a = *x;
+  a = a ? a : -1;
+  *x = a;
+}
+
+void
+test (V *x, V *y)
+{
+  foo<0> (x);
+  bar<V> (y);
+}

	Jakub

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

* Re: [C++ PATCH] Fix up vector cond expr handling in templates (PR c++/71871)
  2016-07-14 15:21 [C++ PATCH] Fix up vector cond expr handling in templates (PR c++/71871) Jakub Jelinek
@ 2016-07-18 17:19 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2016-07-18 17:19 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Marc Glisse, gcc-patches List

OK.

Jason

On Thu, Jul 14, 2016 at 11:21 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> This patch reverts part of
> https://gcc.gnu.org/ml/gcc-patches/2012-10/msg01665.html
> which looks wrong to me.
> The problem is that in templates, if the build_x_conditional_expr
> arguments aren't type dependent, we might get NON_DEPENDENT_EXPR
> wrappers around the argument, so after issuing possibly needed diagnostics
> we need to return back to the original unmodified arguments,
> which for VEC_COND_EXPR the condition has been bypassing and we ended up
> with NON_DEPENDENT_EXPR in the IL, which nothing strips away
> (plus VEC_COND_EXPR isn't really supported in tsubst_copy/tsubst_copy_and_build
> and perhaps other spots).
> While we could do build_min_non_dep with VEC_COND_EXPR and teach pt.c about
> VEC_COND_EXPR, I really don't see advantages of doing that, if we build just
> COND_EXPR, build_min_non_dep ensures that it will have the right type, and
> when we instantiate it build_x_conditional_expr will be called again and
> that will create VEC_COND_EXPR when not processing_template_decl.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2016-07-14  Jakub Jelinek  <jakub@redhat.com>
>
>         PR c++/71871
>         * typeck.c (build_x_conditional_expr): Revert the 2012-10-25 change.
>
>         * g++.dg/ext/vector31.C: New test.
>
> --- gcc/cp/typeck.c.jj  2016-07-11 11:14:28.000000000 +0200
> +++ gcc/cp/typeck.c     2016-07-14 12:47:48.436699222 +0200
> @@ -6288,8 +6288,7 @@ build_x_conditional_expr (location_t loc
>      }
>
>    expr = build_conditional_expr (loc, ifexp, op1, op2, complain);
> -  if (processing_template_decl && expr != error_mark_node
> -      && TREE_CODE (expr) != VEC_COND_EXPR)
> +  if (processing_template_decl && expr != error_mark_node)
>      {
>        tree min = build_min_non_dep (COND_EXPR, expr,
>                                     orig_ifexp, orig_op1, orig_op2);
> --- gcc/testsuite/g++.dg/ext/vector31.C.jj      2016-07-14 13:01:04.933206583 +0200
> +++ gcc/testsuite/g++.dg/ext/vector31.C 2016-07-14 13:00:59.943272143 +0200
> @@ -0,0 +1,29 @@
> +// PR c++/71871
> +// { dg-do compile }
> +
> +typedef unsigned int V __attribute__ ((__vector_size__ (32)));
> +
> +template <int N>
> +void
> +foo (V *x)
> +{
> +  V a = *x;
> +  a = a ? a : -1;
> +  *x = a;
> +}
> +
> +template <typename T>
> +void
> +bar (T *x)
> +{
> +  T a = *x;
> +  a = a ? a : -1;
> +  *x = a;
> +}
> +
> +void
> +test (V *x, V *y)
> +{
> +  foo<0> (x);
> +  bar<V> (y);
> +}
>
>         Jakub

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

end of thread, other threads:[~2016-07-18 17:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-14 15:21 [C++ PATCH] Fix up vector cond expr handling in templates (PR c++/71871) Jakub Jelinek
2016-07-18 17:19 ` 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).