From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1005) id 72181387084E; Thu, 16 Apr 2020 22:54:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 72181387084E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587077680; bh=BG41OmMvX1Goo3mdfodYj3M7daEbwLt4nI+aQEcXzrE=; h=From:To:Subject:Date:From; b=Wz37ZqnYW7xIrbPsVS7nigjcaM4JCTN6E6Zagl5fa0J9eBkVOeGYuvizM3eRJngwG 8XfKR6AH64MZPjPRbo4/aWK+iAhUEkT+BqqmbUfqbU5B6O/MHavzG1GgYKsRygy/jR JbWA/NbPspevIabjj38Eals47LYUne1imzyKd2RY= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Michael Meissner To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/meissner/heads/ieee)] c++: Fix crash in gimplifier with paren init of aggregates [PR94155] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/users/meissner/heads/ieee X-Git-Oldrev: c72a1b6f8b26de37d1a922a8af143af009747498 X-Git-Newrev: f84aded848f6fdd2704c9376263c6d1aee6bb0ca Message-Id: <20200416225440.72181387084E@sourceware.org> Date: Thu, 16 Apr 2020 22:54:40 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Apr 2020 22:54:40 -0000 https://gcc.gnu.org/g:f84aded848f6fdd2704c9376263c6d1aee6bb0ca commit f84aded848f6fdd2704c9376263c6d1aee6bb0ca Author: Marek Polacek Date: Mon Mar 30 15:49:17 2020 -0400 c++: Fix crash in gimplifier with paren init of aggregates [PR94155] Here we crash in the gimplifier because gimplify_init_ctor_eval doesn't expect null indexes for a constructor: /* ??? Here's to hoping the front end fills in all of the indices, so we don't have to figure out what's missing ourselves. */ gcc_assert (purpose); The indexes weren't filled because we never called reshape_init: for a constructor that represents parenthesized initialization of an aggregate we don't allow brace elision or designated initializers. PR c++/94155 - crash in gimplifier with paren init of aggregates. * init.c (build_vec_init): Fill in indexes. * g++.dg/cpp2a/paren-init22.C: New test. Diff: --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/init.c | 2 ++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp2a/paren-init22.C | 15 +++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a382235d7cc..fc75879d14f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2020-04-04 Marek Polacek + Jason Merrill + + PR c++/94155 - crash in gimplifier with paren init of aggregates. + * init.c (build_vec_init): Fill in indexes. + 2020-04-04 Jason Merrill PR c++/91377 diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 27623cf4db1..ea95a3bc910 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -4438,6 +4438,8 @@ build_vec_init (tree base, tree maxindex, tree init, errors = true; if (try_const) { + if (!field) + field = size_int (idx); tree e = maybe_constant_init (one_init); if (reduced_constant_expression_p (e)) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 88bab5d3d19..29830633d79 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-04-04 Marek Polacek + + PR c++/94155 - crash in gimplifier with paren init of aggregates. + * g++.dg/cpp2a/paren-init22.C: New test. + 2020-04-05 Iain Sandoe * g++.dg/coroutines/torture/co-await-14-template-traits.C: Rename... diff --git a/gcc/testsuite/g++.dg/cpp2a/paren-init22.C b/gcc/testsuite/g++.dg/cpp2a/paren-init22.C new file mode 100644 index 00000000000..1b2959e7731 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/paren-init22.C @@ -0,0 +1,15 @@ +// PR c++/94155 - crash in gimplifier with paren init of aggregates. +// { dg-do compile { target c++2a } } + +struct S { int i, j; }; + +struct A { + S s; + constexpr A(S e) : s(e) {} +}; + +void +f() +{ + A g[1]({{1, 1}}); +}