From patchwork Tue Jun 30 17:53:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1320038 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=uKWBwKya; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49xBmK0kFyz9s6w for ; Wed, 1 Jul 2020 03:53:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 31CF83858D37; Tue, 30 Jun 2020 17:53:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by sourceware.org (Postfix) with ESMTPS id A8FAB3858D35 for ; Tue, 30 Jun 2020 17:53:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A8FAB3858D35 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-qt1-x836.google.com with SMTP id o38so16267982qtf.6 for ; Tue, 30 Jun 2020 10:53:14 -0700 (PDT) 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=NH7U0RTw0FIbjmRWLqmaWLFSYqsxH3mm6UmtQUxFxmU=; b=uKWBwKya5tX9oWlUu65tck9Gj/QsiodRC9sMIqxOUfEbBNt4IhBrsI5p/3v9iwHAzl l7rkFwJvsq2POpZmLfuygi6p62VpUQY5aKyh2D39xMxB4eC05Nlm6rerSN9sOJb3C2rt wuCT8R1vG0Izuy1jtTIvTxGFn+/wwnCFfbsTrLcwG6g1W9a+Oks9lpPqH1W/1JV+zPK9 TH17vtmkSwkKFmNO7rgQNrA/fvQCUkWgShozNP7ARPWN3DIniM9rBtrFkCVTJRq0lpmF j0ZuNWnV7FxwwnEJcNQIN/5n8PkQgJPNEVNMJT6sUT7dOSbJRIc/XsMc298iVyT54nez 1aCA== 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=NH7U0RTw0FIbjmRWLqmaWLFSYqsxH3mm6UmtQUxFxmU=; b=ns47auPafz1tZOhT5HMfm9UHAqmYHOMkSTBdtf4OXbQzLaQigm5CUb56hpXY3+ft+q lY7vXu4CAz0Emb91rpWuXKvPpQN//dufq7VLGWJCEbjUiuNNNv+O3ZtxtbvWCrzC4Zxr qZK4uymCcI8ct17+8+x/+ileXjMZZNEh5r8VE4Z1OlS4Z3ETk3KXSq6OH28VWdROtVvg VxMM9OBBCGP74sgTFPddePAqfLkF6bJkK09EOKbmZoa6pYxETJ5mbitNRfewQENZhFpr SspY2B5rztDJc9cv5v/AC1uZPqnMpbG3FoAAPLsE599pkSpH4C0+brUBtrC6vT8yrccR GU8w== X-Gm-Message-State: AOAM5305sZ0AhT5k+QPrbbahZEM9+PzfOfNiKDdrsNn+ac3qQxDqf3MO FlgCWorCAxvnuHVfzU3o/d0= X-Google-Smtp-Source: ABdhPJyqdLiBX682id0nO/JYBc1/auvxSXogYjgpkxrOEHzj9KIDt5t2hPHokcx0uVtBiaIVg1BMTA== X-Received: by 2002:ac8:a44:: with SMTP id f4mr3507106qti.348.1593539593821; Tue, 30 Jun 2020 10:53:13 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:fd7b:3307:e776:82b9? ([2620:10d:c091:480::1:2769]) by smtp.googlemail.com with ESMTPSA id g5sm3964233qta.46.2020.06.30.10.53.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Jun 2020 10:53:12 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: c++: Tweak function cloning names Message-ID: Date: Tue, 30 Jun 2020 13:53:11 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-10.4 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" On the modules branch I need to expose an intermediate step of the function cloning, but before that it'd be nice to rationalize the names somewhat, now that we also use that API for copying the equality operator. Jason's recent patch caused me some pain by altering the same code. I can only blame myself for not pushing some bits sooner. Anyway, this patch makes the newly renamed copy_fndecl_with_name static, and adds a wrapper copy_operator_fn, that takes an operator code. The cdtor cloning functions are renamed to explicitly note they expect cdtors. A followup patch will move some of the logic from copy_fndecl_with_name to build_cdtor_clones. gcc/cp/ * cp-tree.h (copy_fndecl_with_name): Rename to ... (copy_operatorn_fn): ... this. Change arg type. (clone_function_decl): Rename to ... (clone_cdtor): ... this. * class.c (copy_fndecl_with_name): Make static. (copy_operator_fn): New wrapper. (build_clones): Rename to ... (build_cdtor_clones): ... this. (clone_function_decl): Rename to ... (clone_cdtor): ... this. Adjust build_clones calls. (clone_constructors_and_destructors): Adjust clone_function_decl calls. * method.c (implicitly_declare_fn): Adjust copy_fndecl_with_name call. (lazily_declare_fn): Adjust clone_function_decl call. * pt.c (tsubst_function_decl): Likewise. (instantiate_template_1): Likewise. libcc1/ * libcp1plugin.cc (plugin_build_decl): Adjust clone_function_decl call. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 94a95854e25..b0cc027e0de 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -4696,7 +4696,7 @@ check_methods (tree t) } } -tree +static tree copy_fndecl_with_name (tree fn, tree name) { /* Copy the function. */ @@ -4804,6 +4804,14 @@ copy_fndecl_with_name (tree fn, tree name) return clone; } +/* FN is an operator function, create a variant for CODE. */ + +tree +copy_operator_fn (tree fn, tree_code code) +{ + return copy_fndecl_with_name (fn, ovl_op_identifier (code)); +} + /* FN is a constructor or destructor. Clone the declaration to create a specialized in-charge or not-in-charge version, as indicated by NAME. */ @@ -4847,8 +4855,8 @@ build_clone (tree fn, tree name) /* Build the clones of FN, return the number of clones built. These will be inserted onto DECL_CHAIN of FN. */ -unsigned -build_clones (tree fn) +static unsigned +build_cdtor_clones (tree fn) { unsigned count = 0; @@ -4891,14 +4899,14 @@ build_clones (tree fn) CLASSTYPE_MEMBER_VEC. */ void -clone_function_decl (tree fn, bool update_methods) +clone_cdtor (tree fn, bool update_methods) { /* Avoid inappropriate cloning. */ if (DECL_CHAIN (fn) && DECL_CLONED_FUNCTION_P (DECL_CHAIN (fn))) return; - unsigned count = build_clones (fn); + unsigned count = build_cdtor_clones (fn); /* Note that this is an abstract function that is never emitted. */ DECL_ABSTRACT_P (fn) = true; @@ -4998,10 +5006,10 @@ clone_constructors_and_destructors (tree t) /* While constructors can be via a using declaration, at this point we no longer need to know that. */ for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter) - clone_function_decl (*iter, /*update_methods=*/true); + clone_cdtor (*iter, /*update_methods=*/true); if (tree dtor = CLASSTYPE_DESTRUCTOR (t)) - clone_function_decl (dtor, /*update_methods=*/true); + clone_cdtor (dtor, /*update_methods=*/true); } /* Deduce noexcept for a destructor DTOR. */ diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 78e8ca4150a..9b31eaf4a07 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6450,8 +6450,8 @@ extern void check_abi_tags (tree); extern tree missing_abi_tags (tree); extern void fixup_type_variants (tree); extern void fixup_attribute_variants (tree); -extern tree copy_fndecl_with_name (tree, tree); -extern void clone_function_decl (tree, bool); +extern void clone_cdtor (tree, bool); +extern tree copy_operator_fn (tree, tree_code code); extern void adjust_clone_args (tree); extern void deduce_noexcept_on_destructor (tree); extern bool uniquely_derived_from_p (tree, tree); diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 2a98907bfa1..8fd7052d205 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -2688,7 +2688,7 @@ implicitly_declare_fn (special_function_kind kind, tree type, comparison operator function. --end note] */ if (kind == sfk_comparison) { - fn = copy_fndecl_with_name (pattern_fn, ovl_op_identifier (EQ_EXPR)); + fn = copy_operator_fn (pattern_fn, EQ_EXPR); DECL_ARTIFICIAL (fn) = 1; TREE_TYPE (fn) = change_return_type (boolean_type_node, TREE_TYPE (fn)); return fn; @@ -3152,7 +3152,7 @@ lazily_declare_fn (special_function_kind sfk, tree type) maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0); if (DECL_MAYBE_IN_CHARGE_CDTOR_P (fn)) /* Create appropriate clones. */ - clone_function_decl (fn, /*update_methods=*/true); + clone_cdtor (fn, /*update_methods=*/true); return fn; } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 618bf68b2d6..b6423f7432b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -13923,7 +13923,7 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain, If it isn't, that'll be handled by clone_constructors_and_destructors. */ if (PRIMARY_TEMPLATE_P (gen_tmpl)) - clone_function_decl (r, /*update_methods=*/false); + clone_cdtor (r, /*update_methods=*/false); } else if ((complain & tf_error) != 0 && IDENTIFIER_ANY_OP_P (DECL_NAME (r)) @@ -20769,7 +20769,7 @@ instantiate_template_1 (tree tmpl, tree orig_args, tsubst_flags_t complain) instantiating the template clones. */ if (tree chain = DECL_CHAIN (gen_tmpl)) if (DECL_P (chain) && DECL_CLONED_FUNCTION_P (chain)) - clone_function_decl (fndecl, /*update_methods=*/false); + clone_cdtor (fndecl, /*update_methods=*/false); if (!access_ok) { diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc index 00449f43b52..01aecf00735 100644 --- a/libcc1/libcp1plugin.cc +++ b/libcc1/libcp1plugin.cc @@ -1552,7 +1552,7 @@ plugin_build_decl (cc1_plugin::connection *self, reversal. */ tree save = DECL_CHAIN (decl); DECL_CHAIN (decl) = NULL_TREE; - clone_function_decl (decl, /*update_methods=*/true); + clone_cdtor (decl, /*update_methods=*/true); gcc_assert (TYPE_FIELDS (current_class_type) == decl); TYPE_FIELDS (current_class_type) = nreverse (TYPE_FIELDS (current_class_type));