From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id D82073945C34 for ; Mon, 6 Apr 2020 15:57:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D82073945C34 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-314-ydCDR0DrNRSX7FSIKoQJag-1; Mon, 06 Apr 2020 11:57:19 -0400 X-MC-Unique: ydCDR0DrNRSX7FSIKoQJag-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C9CD100550D for ; Mon, 6 Apr 2020 15:57:18 +0000 (UTC) Received: from redhat.com (ovpn-112-192.phx2.redhat.com [10.3.112.192]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A931860BFB; Mon, 6 Apr 2020 15:57:17 +0000 (UTC) Date: Mon, 6 Apr 2020 11:57:15 -0400 From: Marek Polacek To: Jason Merrill Cc: GCC Patches Subject: Re: [PATCH v3] c++: Fix crash in gimplifier with paren init of aggregates [PR94155] Message-ID: <20200406155715.GC633012@redhat.com> References: <20200330202823.428754-1-polacek@redhat.com> <20200404010813.GV2929@redhat.com> <79f201f2-3932-b10c-7f78-afda837c93e4@redhat.com> <20200404175638.GA633012@redhat.com> <6d6371fa-429a-e061-337c-16235e1a94af@redhat.com> MIME-Version: 1.0 In-Reply-To: <6d6371fa-429a-e061-337c-16235e1a94af@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Spam-Status: No, score=-30.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Apr 2020 15:57:22 -0000 On Mon, Apr 06, 2020 at 10:47:49AM -0400, Jason Merrill via Gcc-patches wro= te: > On 4/4/20 1:56 PM, Marek Polacek wrote: > > On Fri, Apr 03, 2020 at 10:39:49PM -0400, Jason Merrill via Gcc-patches= wrote: > > > On 4/3/20 9:08 PM, Marek Polacek wrote: > > > > On Fri, Apr 03, 2020 at 03:01:37PM -0400, Jason Merrill via Gcc-pat= ches wrote: > > > > > On 3/30/20 4:28 PM, Marek Polacek wrote: > > > > > > Here we crash in the gimplifier because gimplify_init_ctor_eval= doesn't > > > > > > expect null indexes for a constructor: > > > > > >=20 > > > > > > /* ??? Here's to hoping the front end fills in all of = the indices, > > > > > > so we don't have to figure out what's missing ourse= lves. */ > > > > > > gcc_assert (purpose); > > > > > >=20 > > > > > > The indexes weren't filled because we never called reshape_init= : for > > > > > > a constructor that represents parenthesized initialization of a= n > > > > > > aggregate we don't allow brace elision or designated initialize= rs. So > > > > > > fill in the indexes manually, here we have an array, and we can= simply > > > > > > assign indexes starting from 0. > > > > > >=20 > > > > > > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > > > >=20 > > > > > Shouldn't digest_init fill in the indexes? In > > > > > process_init_constructor_array I see > > > > >=20 > > > > > if (!ce->index) > > > > > ce->index =3D size_int (i); > > > >=20 > > > > Yes, that works too. Thus: > > > >=20 > > > > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > > >=20 > > > > -- >8 -- > > > > Here we crash in the gimplifier because gimplify_init_ctor_eval doe= sn't > > > > expect null indexes for a constructor: > > > >=20 > > > > /* ??? Here's to hoping the front end fills in all of the i= ndices, > > > > so we don't have to figure out what's missing ourselves.= */ > > > > gcc_assert (purpose); > > > >=20 > > > > The indexes weren't filled because we never called reshape_init: fo= r > > > > a constructor that represents parenthesized initialization of an > > > > aggregate we don't allow brace elision or designated initializers. = So > > > > call digest_init to fill in the indexes. > > > >=20 > > > > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > > >=20 > > > > =09PR c++/94155 - crash in gimplifier with paren init of aggregates= . > > > > =09* decl.c (check_initializer): Call digest_init. > > > >=20 > > > > =09* g++.dg/cpp2a/paren-init22.C: New test. > > > > --- > > > > gcc/cp/decl.c | 5 +++++ > > > > gcc/testsuite/g++.dg/cpp2a/paren-init22.C | 15 +++++++++++++++ > > > > 2 files changed, 20 insertions(+) > > > > create mode 100644 gcc/testsuite/g++.dg/cpp2a/paren-init22.C > > > >=20 > > > > diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c > > > > index 69a238997b4..63e7bda09f5 100644 > > > > --- a/gcc/cp/decl.c > > > > +++ b/gcc/cp/decl.c > > > > @@ -6754,6 +6754,11 @@ check_initializer (tree decl, tree init, int= flags, vec **cleanups) > > > > =09 init =3D build_constructor_from_list (init_list_type_no= de, init); > > > > =09 CONSTRUCTOR_IS_DIRECT_INIT (init) =3D true; > > > > =09 CONSTRUCTOR_IS_PAREN_INIT (init) =3D true; > > > > +=09 /* The gimplifier expects that the front end fills in all= of the > > > > +=09=09 indices. Normally, reshape_init_array fills these in, but = we > > > > +=09=09 don't call reshape_init because that does nothing when it g= ets > > > > +=09=09 CONSTRUCTOR_IS_PAREN_INIT. */ > > > > +=09 init =3D digest_init (type, init, tf_warning_or_error); > > >=20 > > > But why weren't we already calling digest_init in store_init_value? = Was the > > > CONSTRUCTOR making it all the way to gimplification still having > > > init_list_type_node? > >=20 > > It's because we set LOOKUP_ALREADY_DIGESTED a few lines below: > > 6813 /* Don't call digest_init; it's unnecessary and wi= ll complain > > 6814 about aggregate initialization of non-aggregate= classes. */ > > 6815 flags |=3D LOOKUP_ALREADY_DIGESTED; > > and so store_init_value doesn't digest. Given the comment I'd be nervo= us about > > not setting that flag here. >=20 > OK, then why isn't it called by build_aggr_init? How is the CONSTRUCTOR > getting a type without this being fixed up? >=20 > ... >=20 > Ah, because build_vec_init builds up a new CONSTRUCTOR and gives it a typ= e > without setting the indexes like process_init_constructor_array does: >=20 > Jason > 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= , > =09 errors =3D true; > =09 if (try_const) > =09 { > +=09 if (!field) > +=09=09field =3D size_int (idx); > =09 tree e =3D maybe_constant_init (one_init); > =09 if (reduced_constant_expression_p (e)) > =09=09{ That works, thanks for figuring that out. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- 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. =09PR c++/94155 - crash in gimplifier with paren init of aggregates. =09* init.c (build_vec_init): Fill in indexes. =09* g++.dg/cpp2a/paren-init22.C: New test. --- gcc/cp/init.c | 2 ++ gcc/testsuite/g++.dg/cpp2a/paren-init22.C | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/paren-init22.C 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, =09 errors =3D true; =09 if (try_const) =09 { +=09 if (!field) +=09=09field =3D size_int (idx); =09 tree e =3D maybe_constant_init (one_init); =09 if (reduced_constant_expression_p (e)) =09=09{ 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}}); +} base-commit: c72a1b6f8b26de37d1a922a8af143af009747498 --=20 Marek Polacek =E2=80=A2 Red Hat, Inc. =E2=80=A2 300 A St, Boston, MA