public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-6320] c++: Fix constexpr array ICE [PR98332]
Date: Wed, 23 Dec 2020 21:40:40 +0000 (GMT)	[thread overview]
Message-ID: <20201223214040.ED67A3857004@sourceware.org> (raw)

https://gcc.gnu.org/g:6b7d53a25933f4aed71d6d5134e971bd995f8973

commit r11-6320-g6b7d53a25933f4aed71d6d5134e971bd995f8973
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Dec 22 16:40:37 2020 -0500

    c++: Fix constexpr array ICE [PR98332]
    
    The element initializer was non-constant, so its CONSTRUCTOR element ended
    up NULL, so unshare_constructor crashed trying to look at it.  This patch
    fixes this in two places: First, by returning when we see a non-constant
    initializer; second, by not crashing on NULL.
    
    gcc/cp/ChangeLog:
    
            PR c++/98332
            * constexpr.c (unshare_constructor): Check for NULL.
            (cxx_eval_vec_init_1): Always exit early if non-constant.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/98332
            * g++.dg/cpp0x/constexpr-overflow3.C: New test.

Diff:
---
 gcc/cp/constexpr.c                               | 4 ++--
 gcc/testsuite/g++.dg/cpp0x/constexpr-overflow3.C | 5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index b6f3e6e7a31..f7cc4132085 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1524,7 +1524,7 @@ unshare_constructor (tree t MEM_STAT_DECL)
       vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (n);
       constructor_elt *ce;
       for (HOST_WIDE_INT i = 0; vec_safe_iterate (v, i, &ce); ++i)
-	if (TREE_CODE (ce->value) == CONSTRUCTOR)
+	if (ce->value && TREE_CODE (ce->value) == CONSTRUCTOR)
 	  ptrs.safe_push (&ce->value);
     }
   return t;
@@ -4548,7 +4548,7 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init,
 	  eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval,
 						  non_constant_p, overflow_p);
 	}
-      if (*non_constant_p && !ctx->quiet)
+      if (*non_constant_p)
 	break;
       if (new_ctx.ctor != ctx->ctor)
 	{
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-overflow3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-overflow3.C
new file mode 100644
index 00000000000..22d4c59f4f8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-overflow3.C
@@ -0,0 +1,5 @@
+// PR c++/98332
+// { dg-do compile { target c++11 } }
+
+struct S { int a = 2147483647 + 1; }; // { dg-warning "overflow" }
+struct { S b[2][1][1][1]; } c;


                 reply	other threads:[~2020-12-23 21:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201223214040.ED67A3857004@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).