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 1C9A5385BF83 for ; Mon, 6 Apr 2020 22:22:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1C9A5385BF83 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-422-7-0o4iA-N22vfL6EgbQVfA-1; Mon, 06 Apr 2020 18:22:30 -0400 X-MC-Unique: 7-0o4iA-N22vfL6EgbQVfA-1 Received: by mail-qv1-f72.google.com with SMTP id m11so1234017qvf.20 for ; Mon, 06 Apr 2020 15:22:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=u8DjW58pB2i2SBS61A3IcvBU5T2QTj1qRzvE0fhnWq8=; b=cwHV/L+ECI6mABvi7mpUsPoemGQh9diiKD5LjDC3IF9CFf3EYwaFqXbEoXUdMgsFJO hzH1LJxKW8x5Gx3Qm9hHtHoOMKlVQ8FIOZl6nuh6mRSD1pkHjTqSV6KncDUEEBNRYc7w L1+QoHePPoS13fiBnmSVps6qwuFTpKFsxevIqH6WStpQgFehkuBJzwwLeKBKMlnH742Y b7Nyjjud32l+JUw1dIlXGondUgoEOaSeAv+eIpTCNT85r3fr91vCpW4kxAAy0z5P6yLT CYwsTUFi7KJPGocEzguxjgw6eyCWt42vjZ1B5VAepm1BLUzkSljP1iiRBJ/kKA1oJqIe 2qwg== X-Gm-Message-State: AGi0PuZMgSc4asL3HC7AgB+zLOTm1fX6b/F+H/6yg4v/1YqKdutIOjHo w/w/TC1YIpo8mjd04Tq6rDpRoVGgUZki+MI8mdl6qXxmzAIZsS2+tjB+Krg1TyyaPzUPKg85oOH jsV7WYtFOt4Y/UVm+pg== X-Received: by 2002:a05:620a:15f4:: with SMTP id p20mr7708169qkm.496.1586211750158; Mon, 06 Apr 2020 15:22:30 -0700 (PDT) X-Google-Smtp-Source: APiQypKKSJac+2HmoJX+lsOODLZZ4zxKQJI6ohdZBd5C3PTv8BK5K+Pl0cHHi9U3A/yIbNEn58hD7Q== X-Received: by 2002:a05:620a:15f4:: with SMTP id p20mr7708140qkm.496.1586211749726; Mon, 06 Apr 2020 15:22:29 -0700 (PDT) Received: from [192.168.1.130] (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id o205sm7664061qke.41.2020.04.06.15.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Apr 2020 15:22:29 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Mon, 6 Apr 2020 18:22:28 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: Fix usage of CONSTRUCTOR_PLACEHOLDER_BOUNDARY inside array initializers [90996] In-Reply-To: Message-ID: References: <20200406190756.1798784-1-ppalka@redhat.com> User-Agent: Alpine 2.22 (DEB 413 2020-03-19) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-30.1 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 22:22:35 -0000 On Mon, 6 Apr 2020, Jason Merrill wrote: > On 4/6/20 3:07 PM, Patrick Palka wrote: > > This PR reports that since the introduction of the > > CONSTRUCTOR_PLACEHOLDER_BOUNDARY flag, we are sometimes failing to reso= lve > > PLACEHOLDER_EXPRs inside array initializers that refer to some inner > > constructor. In the testcase in the PR, we have as the initializer for= "S > > c[];" > > the following > >=20 > > {{.a=3D(int &) &_ZGR1c_, .b=3D{*(&)->a}}} > >=20 > > where CONSTRUCTOR_PLACEHOLDER_BOUNDARY is set on the second outermost > > constructor. However, we pass the whole initializer to replace_placeho= lders > > in > > store_init_value, and so due to the flag being set on the second outerm= ost > > ctor > > it avoids recursing into the innermost constructor and we fail to resol= ve > > the > > PLACEHOLDER_EXPR within. > >=20 > > To fix this, we could perhaps either call replace_placeholders in more > > places, > > or we could change where we set CONSTRUCTOR_PLACEHOLDER_BOUNDARY. This > > patch > > takes the latter approach -- when building up an array initializer, it > > bubbles > > any CONSTRUCTOR_PLACEHOLDER_BOUNDARY flag set on the element initialize= rs up > > to > > the array initializer. Doing so shouldn't create any new PLACEHOLDER_E= XPR > > resolution ambiguities because we don't deal with PLACEHOLDER_EXPRs of = array > > type in the frontend, as far as I can tell. >=20 > Interesting. Yes, that sounds like it should work. >=20 > > Does this look OK to comit after testing? >=20 > Yes. >=20 > Though I'm seeing "after testing" a lot; what testing are you doing befor= e > sending patches? Sorry for the sloppiness -- I should be writing "after a full bootstrap/regtest" instead of "after testing" because I do indeed do some testing before sending a patch. In particular, I usually run and inspect the outputs of make check RUNTESTFLAGS=3D"dg.exp=3D*.C" make check RUNTESTFLAGS=3D"old-deja.exp=3D*.C" make check RUNTESTFLAGS=3D"conformance.exp=3D*ranges*" in a build tree that is configured with --disable-bootstrap, as a quick smoke test for the patch. Is this a sufficient amount of testing before sending a patch for review, or would you prefer that I do a full bootstrap/regtest beforehand? In any case, I'll make sure to clearly convey the amount of testing that was done and is remaining in future patch submissions. >=20 > > gcc/cp/ChangeLog: > >=20 > > =09PR c++/90996 > > =09* tree.c (replace_placeholders): Look through all handled components= , > > =09not just COMPONENT_REFs. > > =09* typeck2.c (process_init_constructor_array): Propagate > > =09CONSTRUCTOR_PLACEHOLDER_BOUNDARY up from each element initializer to > > =09the array initializer. > >=20 > > gcc/testsuite/ChangeLog: > >=20 > > =09PR c++/90996 > > =09* g++.dg/cpp1y/pr90996.C: New test. > > --- > > gcc/cp/tree.c | 2 +- > > gcc/cp/typeck2.c | 18 ++++++++++++++++++ > > gcc/testsuite/g++.dg/cpp1y/pr90996.C | 17 +++++++++++++++++ > > 3 files changed, 36 insertions(+), 1 deletion(-) > > create mode 100644 gcc/testsuite/g++.dg/cpp1y/pr90996.C > >=20 > > diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c > > index 5eb0dcd717a..d1192b7e094 100644 > > --- a/gcc/cp/tree.c > > +++ b/gcc/cp/tree.c > > @@ -3247,7 +3247,7 @@ replace_placeholders (tree exp, tree obj, bool *s= een_p > > /*=3D NULL*/) > > /* If the object isn't a (member of a) class, do nothing. */ > > tree op0 =3D obj; > > - while (TREE_CODE (op0) =3D=3D COMPONENT_REF) > > + while (handled_component_p (op0)) > > op0 =3D TREE_OPERAND (op0, 0); > > if (!CLASS_TYPE_P (strip_array_types (TREE_TYPE (op0)))) > > return exp; > > diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c > > index cf1cb5ace66..fe844bc08bb 100644 > > --- a/gcc/cp/typeck2.c > > +++ b/gcc/cp/typeck2.c > > @@ -1488,6 +1488,17 @@ process_init_constructor_array (tree type, tree = init, > > int nested, int flags, > > =09=3D massage_init_elt (TREE_TYPE (type), ce->value, nested, flags, > > =09=09=09 complain); > > + if (TREE_CODE (ce->value) =3D=3D CONSTRUCTOR > > +=09 && CONSTRUCTOR_PLACEHOLDER_BOUNDARY (ce->value)) > > +=09{ > > +=09 /* Shift CONSTRUCTOR_PLACEHOLDER_BOUNDARY from the element > > initializer > > +=09 up to the array initializer, so that the call to > > +=09 replace_placeholders from store_init_value can resolve any > > +=09 PLACEHOLDER_EXPRs within this element initializer. */ > > +=09 CONSTRUCTOR_PLACEHOLDER_BOUNDARY (ce->value) =3D 0; > > +=09 CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init) =3D 1; > > +=09} > > + > > gcc_checking_assert > > =09(ce->value =3D=3D error_mark_node > > =09 || (same_type_ignoring_top_level_qualifiers_p > > @@ -1516,6 +1527,13 @@ process_init_constructor_array (tree type, tree = init, > > int nested, int flags, > > =09 /* The default zero-initialization is fine for us; don't > > =09=09 add anything to the CONSTRUCTOR. */ > > =09 next =3D NULL_TREE; > > +=09 else if (TREE_CODE (next) =3D=3D CONSTRUCTOR > > +=09=09 && CONSTRUCTOR_PLACEHOLDER_BOUNDARY (next)) > > +=09 { > > +=09=09/* As above. */ > > +=09=09CONSTRUCTOR_PLACEHOLDER_BOUNDARY (next) =3D 0; > > +=09=09CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init) =3D 1; > > +=09 } > > =09 } > > =09else if (!zero_init_p (TREE_TYPE (type))) > > =09 next =3D build_zero_init (TREE_TYPE (type), > > diff --git a/gcc/testsuite/g++.dg/cpp1y/pr90996.C > > b/gcc/testsuite/g++.dg/cpp1y/pr90996.C > > new file mode 100644 > > index 00000000000..780cbb4e3ac > > --- /dev/null > > +++ b/gcc/testsuite/g++.dg/cpp1y/pr90996.C > > @@ -0,0 +1,17 @@ > > +// PR c++/90996 > > +// { dg-do compile { target c++14 } } > > + > > +struct S > > +{ > > + int &&a =3D 2; > > + int b[1] {a}; > > +}; > > + > > +S c[2][2] {{{5}}}; > > + > > +struct T > > +{ > > + S c[2][2] {{{7}}}; > > +}; > > + > > +T d {}; > >=20 >=20 >=20