public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [C++ PATCH] Fix ICE in cxx_eval_vec_init_1 (PR c++/84558)
  2018-02-27  9:50 [C++ PATCH] Fix ICE in cxx_eval_vec_init_1 (PR c++/84558) Jakub Jelinek
@ 2018-02-26 21:50 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2018-02-26 21:50 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Nathan Sidwell, gcc-patches List

OK.

On Mon, Feb 26, 2018 at 2:57 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> The PR70001 optimization in cxx_eval_vec_init_1 uses
> initializer_constant_valid_p (eltinit, TREE_TYPE (eltinit))
> which doesn't work if eltinit is NULL.  This can happen if
> *non_constant_p is true, but ctx->quiet is true as well (for
> *non_constant_p && !ctx->quiet we break the cycle early).
> No initializer can be treated like a valid initializer and will
> have the advantage that we don't repeat the body for every array element
> and just do it once.  The caller will ignore the return value anyway
> when *non_constant_p.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2018-02-26  Jakub Jelinek  <jakub@redhat.com>
>
>         PR c++/84558
>         * constexpr.c (cxx_eval_vec_init_1): For reuse, treat NULL eltinit like
>         a valid constant initializer.  Formatting fixes.
>
>         * g++.dg/cpp1y/pr84558.C: New test.
>
> --- gcc/cp/constexpr.c.jj       2018-02-26 10:46:02.162316172 +0100
> +++ gcc/cp/constexpr.c  2018-02-26 14:07:38.705532369 +0100
> @@ -2959,9 +2959,8 @@ cxx_eval_vec_init_1 (const constexpr_ctx
>           if (!lvalue_p (init))
>             eltinit = move (eltinit);
>           eltinit = force_rvalue (eltinit, tf_warning_or_error);
> -         eltinit = (cxx_eval_constant_expression
> -                    (&new_ctx, eltinit, lval,
> -                     non_constant_p, overflow_p));
> +         eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval,
> +                                                 non_constant_p, overflow_p);
>         }
>        if (*non_constant_p && !ctx->quiet)
>         break;
> @@ -2974,12 +2973,13 @@ cxx_eval_vec_init_1 (const constexpr_ctx
>        else
>         CONSTRUCTOR_APPEND_ELT (*p, idx, eltinit);
>        /* Reuse the result of cxx_eval_constant_expression call
> -         from the first iteration to all others if it is a constant
> -         initializer that doesn't require relocations.  */
> +        from the first iteration to all others if it is a constant
> +        initializer that doesn't require relocations.  */
>        if (reuse
>           && max > 1
> -         && (initializer_constant_valid_p (eltinit, TREE_TYPE (eltinit))
> -             == null_pointer_node))
> +         && (eltinit == NULL_TREE
> +             || (initializer_constant_valid_p (eltinit, TREE_TYPE (eltinit))
> +                 == null_pointer_node)))
>         {
>           if (new_ctx.ctor != ctx->ctor)
>             eltinit = new_ctx.ctor;
> --- gcc/testsuite/g++.dg/cpp1y/pr84558.C.jj     2018-02-26 14:33:56.575318295 +0100
> +++ gcc/testsuite/g++.dg/cpp1y/pr84558.C        2018-02-26 14:33:33.142318527 +0100
> @@ -0,0 +1,6 @@
> +// PR c++/84558
> +// { dg-do compile { target c++14 } }
> +
> +struct A { static int i; constexpr A () { i = 0; } };
> +struct B { A a[2][3][4]; };
> +B b;
>
>         Jakub

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

* [C++ PATCH] Fix ICE in cxx_eval_vec_init_1 (PR c++/84558)
@ 2018-02-27  9:50 Jakub Jelinek
  2018-02-26 21:50 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2018-02-27  9:50 UTC (permalink / raw)
  To: Jason Merrill, Nathan Sidwell; +Cc: gcc-patches

Hi!

The PR70001 optimization in cxx_eval_vec_init_1 uses
initializer_constant_valid_p (eltinit, TREE_TYPE (eltinit))
which doesn't work if eltinit is NULL.  This can happen if
*non_constant_p is true, but ctx->quiet is true as well (for
*non_constant_p && !ctx->quiet we break the cycle early).
No initializer can be treated like a valid initializer and will
have the advantage that we don't repeat the body for every array element
and just do it once.  The caller will ignore the return value anyway
when *non_constant_p.

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

2018-02-26  Jakub Jelinek  <jakub@redhat.com>

	PR c++/84558
	* constexpr.c (cxx_eval_vec_init_1): For reuse, treat NULL eltinit like
	a valid constant initializer.  Formatting fixes.

	* g++.dg/cpp1y/pr84558.C: New test.

--- gcc/cp/constexpr.c.jj	2018-02-26 10:46:02.162316172 +0100
+++ gcc/cp/constexpr.c	2018-02-26 14:07:38.705532369 +0100
@@ -2959,9 +2959,8 @@ cxx_eval_vec_init_1 (const constexpr_ctx
 	  if (!lvalue_p (init))
 	    eltinit = move (eltinit);
 	  eltinit = force_rvalue (eltinit, tf_warning_or_error);
-	  eltinit = (cxx_eval_constant_expression
-		     (&new_ctx, eltinit, lval,
-		      non_constant_p, overflow_p));
+	  eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval,
+						  non_constant_p, overflow_p);
 	}
       if (*non_constant_p && !ctx->quiet)
 	break;
@@ -2974,12 +2973,13 @@ cxx_eval_vec_init_1 (const constexpr_ctx
       else
 	CONSTRUCTOR_APPEND_ELT (*p, idx, eltinit);
       /* Reuse the result of cxx_eval_constant_expression call
-	  from the first iteration to all others if it is a constant
-	  initializer that doesn't require relocations.  */
+	 from the first iteration to all others if it is a constant
+	 initializer that doesn't require relocations.  */
       if (reuse
 	  && max > 1
-	  && (initializer_constant_valid_p (eltinit, TREE_TYPE (eltinit))
-	      == null_pointer_node))
+	  && (eltinit == NULL_TREE
+	      || (initializer_constant_valid_p (eltinit, TREE_TYPE (eltinit))
+		  == null_pointer_node)))
 	{
 	  if (new_ctx.ctor != ctx->ctor)
 	    eltinit = new_ctx.ctor;
--- gcc/testsuite/g++.dg/cpp1y/pr84558.C.jj	2018-02-26 14:33:56.575318295 +0100
+++ gcc/testsuite/g++.dg/cpp1y/pr84558.C	2018-02-26 14:33:33.142318527 +0100
@@ -0,0 +1,6 @@
+// PR c++/84558
+// { dg-do compile { target c++14 } }
+
+struct A { static int i; constexpr A () { i = 0; } };
+struct B { A a[2][3][4]; };
+B b;

	Jakub

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

end of thread, other threads:[~2018-02-27  9:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-27  9:50 [C++ PATCH] Fix ICE in cxx_eval_vec_init_1 (PR c++/84558) Jakub Jelinek
2018-02-26 21: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).