From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 113543 invoked by alias); 15 Dec 2018 22:11:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 113528 invoked by uid 89); 15 Dec 2018 22:11:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=decl_context, DECL_CONTEXT, component_ref, saved X-HELO: mail-ot1-f43.google.com Received: from mail-ot1-f43.google.com (HELO mail-ot1-f43.google.com) (209.85.210.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 15 Dec 2018 22:11:44 +0000 Received: by mail-ot1-f43.google.com with SMTP id u16so8849069otk.8 for ; Sat, 15 Dec 2018 14:11:44 -0800 (PST) MIME-Version: 1.0 References: <81ac6c22-8907-a166-b8df-80e06d2850da@redhat.com> <12883fc9-4e44-e16d-fdc6-9a90c21bf01c@redhat.com> In-Reply-To: From: Jason Merrill Date: Sat, 15 Dec 2018 22:11:00 -0000 Message-ID: Subject: Re: [C++ Patch] [PR c++/88146] do not crash synthesizing inherited ctor(...) To: Alexandre Oliva Cc: gcc-patches List Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2018-12/txt/msg01155.txt.bz2 On Fri, Dec 14, 2018 at 6:05 PM Alexandre Oliva wrote: > > On Dec 14, 2018, Jason Merrill wrote: > > > Let's move the initialization of "fields" inside the 'then' block here > > with the initialization of "cvquals", rather than clear it in the > > 'else'. > > We'd still have to NULL-initialize it somewhere, so I'd rather just move > the entire loop into the conditional, and narrow the scope of variables > only used within the loop, like this. The full patch below is very hard > to read because of the reindentation, so here's a diff -b. > > diff --git a/gcc/cp/method.c b/gcc/cp/method.c > index fd023e200538..17404a65b0fd 100644 > --- a/gcc/cp/method.c > +++ b/gcc/cp/method.c > @@ -675,12 +675,9 @@ do_build_copy_constructor (tree fndecl) > } > else > { > - tree fields = TYPE_FIELDS (current_class_type); > tree member_init_list = NULL_TREE; > - int cvquals = cp_type_quals (TREE_TYPE (parm)); > int i; > tree binfo, base_binfo; > - tree init; > vec *vbases; > > /* Initialize all the base-classes with the parameter converted > @@ -704,15 +701,18 @@ do_build_copy_constructor (tree fndecl) > inh, member_init_list); > } > > - for (; fields; fields = DECL_CHAIN (fields)) > + if (!inh) > + { > + int cvquals = cp_type_quals (TREE_TYPE (parm)); > + > + for (tree fields = TYPE_FIELDS (current_class_type); > + fields; fields = DECL_CHAIN (fields)) > { > tree field = fields; > tree expr_type; > > if (TREE_CODE (field) != FIELD_DECL) > continue; > - if (inh) > - continue; > > expr_type = TREE_TYPE (field); > if (DECL_NAME (field)) > @@ -742,7 +742,7 @@ do_build_copy_constructor (tree fndecl) > expr_type = cp_build_qualified_type (expr_type, quals); > } > > - init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE); > + tree init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE); > if (move_p && !TYPE_REF_P (expr_type) > /* 'move' breaks bit-fields, and has no effect for scalars. */ > && !scalarish_type_p (expr_type)) > @@ -751,6 +751,8 @@ do_build_copy_constructor (tree fndecl) > > member_init_list = tree_cons (field, init, member_init_list); > } > + } > + > finish_mem_initializers (member_init_list); > } > } > @@ -891,6 +893,7 @@ synthesize_method (tree fndecl) > > /* Reset the source location, we might have been previously > deferred, and thus have saved where we were first needed. */ > + if (!DECL_INHERITED_CTOR (fndecl)) > DECL_SOURCE_LOCATION (fndecl) > = DECL_SOURCE_LOCATION (TYPE_NAME (DECL_CONTEXT (fndecl))); > > > Is this OK too? (pending regstrapping) Yes, thanks. Jason