From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by sourceware.org (Postfix) with ESMTPS id 2F4263858001 for ; Tue, 3 Nov 2020 18:19:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2F4263858001 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qv1-xf2f.google.com with SMTP id d1so7652205qvl.6 for ; Tue, 03 Nov 2020 10:19:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=CcahLyLIyERUtq9/38EtM/IN+9dkJl6FRhJm05oAJG0=; b=NafFxzMworAqyf6oPA7y10Lo9nZfHY+QMqoop8S5GZ0ZnhiLkvoDeti4/771bsY01F 1OLzbSH0Z1ziHPFm6JHnksmQ++go8DhiLOlmpjsZnFXS01G0ummdhqpyqnC8ANArJLtn 4YABxs/2xD3mZuD6gZnTjHuLi5n39ClxpLEkJ8TECd/dj1tkk0q1bIj6expe37h8U9S5 BRVk77Hm28AHU5R8LuPvz4Dvv7mrSVEBchWZkxX46kDQrVKAy81xgUVTX6huRZTTZo0q sQt4chEg43MaD6hGv1f6aqEs7MhCGUsPsrFCeXafdRNiS5P/8pQRt7+F9D/QJNLmokGX 0fjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=CcahLyLIyERUtq9/38EtM/IN+9dkJl6FRhJm05oAJG0=; b=NGHgDs0Iciir3UOH+ds8KVjcJTWlEOLFGEtq3V/FF8/hwqJfQxRGyPKO/UHIj6jV+c Sj9fQPWEhLFtMBfhYbFAvzC5/+Q3DcOt0c62Tu7RD6vbDUXy8jwTGUhXoeBqP4E0IU59 QgcFnh0UDA+WRWb/WBDEemqimzEK2czXlwUDLRYv46jwToGtIz/NA1/q94L1pXVtAj2+ 1KAyBdYRsNV2v7ChDSmnMTlY6ZpdFKJusrwgNu1qeVXCTaCxBIexmECVj5Swgb5/jkgG 31M+VlTY5x/uMQYPInV6Cy13c047C0lu5MeLk4NamRGP2w/aKzf5lB9wFFc19hDdsx9U n+Jw== X-Gm-Message-State: AOAM530qG7qeh2THMRp5xMe5xo+H3qJmr3+0JsUljq1yJonB6TGXsbID fbZeBCoLLYcg/FVu5Zib3jI= X-Google-Smtp-Source: ABdhPJx1neGg+eb9qo0y92VLBYxev06WHIOxiGQ0UVZ1+Ut4Z/jfzx99tYw/5nw1sSVh07yx6TqrFw== X-Received: by 2002:a0c:e78d:: with SMTP id x13mr28218111qvn.20.1604427590428; Tue, 03 Nov 2020 10:19:50 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:e5ef:7eb4:1609:98bb? ([2620:10d:c091:480::1:bc2d]) by smtp.googlemail.com with ESMTPSA id z22sm10844524qkg.65.2020.11.03.10.19.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Nov 2020 10:19:49 -0800 (PST) Sender: Nathan Sidwell To: GCC Patches From: Nathan Sidwell Subject: c++: Refactor clone copying Message-ID: Date: Tue, 3 Nov 2020 13:19:48 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------A1E5A00EDAE734D7549A5C6D" Content-Language: en-US X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, 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: Tue, 03 Nov 2020 18:19:52 -0000 This is a multi-part message in MIME format. --------------A1E5A00EDAE734D7549A5C6D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit This patch sets copy_fndecl_with_name to always inform rest_of_decl_compilation that it is not a top-level decl (it's a member function). I also refactor build_cdtor_clones to conditionally do the method vector updating. That happens to be a better interface for modules to use. gcc/cp/ * class.c (copy_fndecl_with_name): Always not top level. (build_cdtor_clones): Add update_methods parm, use it to conditionally update the method vec. Return void (clone_cdtor): Adjust. (clone_constructors_and_destructors): Adjust comment. pushing to trunk nathan -- Nathan Sidwell --------------A1E5A00EDAE734D7549A5C6D Content-Type: text/x-patch; charset=UTF-8; name="class.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="class.diff" diff --git i/gcc/cp/class.c w/gcc/cp/class.c index 6c21682a3e5..c03737294eb 100644 --- i/gcc/cp/class.c +++ w/gcc/cp/class.c @@ -4838,7 +4838,10 @@ copy_fndecl_with_name (tree fn, tree name, tree_code code, /* Create the RTL for this function. */ SET_DECL_RTL (clone, NULL); - rest_of_decl_compilation (clone, namespace_bindings_p (), at_eof); + + /* Regardless of the current scope, this is a member function, so + not at namespace scope. */ + rest_of_decl_compilation (clone, /*top_level=*/0, at_eof); return clone; } @@ -4898,8 +4901,9 @@ build_clone (tree fn, tree name, bool need_vtt_parm_p, /* Build the clones of FN, return the number of clones built. These will be inserted onto DECL_CHAIN of FN. */ -static unsigned -build_cdtor_clones (tree fn, bool needs_vtt_p, bool base_omits_inherited_p) +static void +build_cdtor_clones (tree fn, bool needs_vtt_p, bool base_omits_inherited_p, + bool update_methods) { unsigned count = 0; @@ -4935,7 +4939,16 @@ build_cdtor_clones (tree fn, bool needs_vtt_p, bool base_omits_inherited_p) count += 2; } - return count; + /* The original is now an abstract function that is never + emitted. */ + DECL_ABSTRACT_P (fn) = true; + + if (update_methods) + for (tree clone = fn; count--;) + { + clone = DECL_CHAIN (clone); + add_method (DECL_CONTEXT (clone), clone, false); + } } /* Produce declarations for all appropriate clones of FN. If @@ -4958,17 +4971,7 @@ clone_cdtor (tree fn, bool update_methods) bool base_omits_inherited = (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn) && base_ctor_omit_inherited_parms (fn)); - unsigned count = build_cdtor_clones (fn, vtt, base_omits_inherited); - - /* Note that this is an abstract function that is never emitted. */ - DECL_ABSTRACT_P (fn) = true; - - if (update_methods) - for (tree clone = fn; count--;) - { - clone = DECL_CHAIN (clone); - add_method (DECL_CONTEXT (clone), clone, false); - } + build_cdtor_clones (fn, vtt, base_omits_inherited, update_methods); } /* DECL is an in charge constructor, which is being defined. This will @@ -5055,8 +5058,8 @@ adjust_clone_args (tree decl) static void clone_constructors_and_destructors (tree t) { - /* While constructors can be via a using declaration, at this point - we no longer need to know that. */ + /* We do not need to propagate the usingness to the clone, at this + point that is not needed. */ for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter) clone_cdtor (*iter, /*update_methods=*/true); --------------A1E5A00EDAE734D7549A5C6D--