From patchwork Tue Oct 25 20:16:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 10973 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1197877wru; Tue, 25 Oct 2022 13:16:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6FimjAdjq1eQN5/S/9DzYpj/ToDfOjHrpH1SdtrF1lo+Cid3R4TAXzTu/NhsOqsOrHLVXG X-Received: by 2002:a05:6402:26c9:b0:461:d6a4:afc1 with SMTP id x9-20020a05640226c900b00461d6a4afc1mr10035391edd.385.1666729018377; Tue, 25 Oct 2022 13:16:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666729018; cv=none; d=google.com; s=arc-20160816; b=NsXdCNiQ4N7OFB9BccwGoXdevmlcb9YFNySEOkUvdOZ3xJBajrjkoWDHjkSC87+ELE 2MlFY55yFaBdAJ7F/Z2xZ7lqRF5NuX7/rtATqTWbm8aEcH3eshdUiPp6ms6FBn452h0Q dz0TJzcEk3mZ8FGaO7GFjvmT0Ux7sWS91HAdnAc/O8Ij7795ApUhsxFGnMrbYaAFtme2 eYLxmrEv0xUTCKUcCM1VuYnZGLGxI6D/ZfL/fvmYEkTWtT9x0OOYQeD1IAEmZJruRCfr FRx+puPzcYAHo2Y4rsPQc3vyuz996ITfhh0MgXPWs8tHKq6Mekt9eogJFvHXx+mGZIyK HJbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :content-language:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=1fxEhcneJjMBTg+E3RF7nPCfWEB16oCd3Fy8y169+Is=; b=pb4QbqfBHkSUW2U+m/jQvCGLMY1A7zQ2d6I7sJFjwpbyNJulGLqOhYvDCS9YOVi3my cQFpGZuEeJ+C3s762cG0ws4KbzLtuqyNIX4t9L26VzGf/QsJ3rfKgJD2caMgCn8wnCBi vpflqM1ExqdYzQLUua2hGNtiEnVy+CrjuUuDpjmVCCRRtXI7dXWbC/nX/d8QkHi0K1W4 txkdyI2vPAgJhqKGhe/LQjre6AMYUMf9Ur39+sZlxuwHgpbN93VqRNuqX8lpv4KlxVEu M0jLG8SWhNNCI+CBNg8k8dP8+cUsr+nJKSqSBVDYasLQcD+FOwpYLdKfTR2XDy9LxtdL Lw4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BaYVxtYA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b91-20020a509f64000000b0045f5118c39fsi3367543edf.367.2022.10.25.13.16.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 13:16:58 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BaYVxtYA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5DED73857835 for ; Tue, 25 Oct 2022 20:16:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DED73857835 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666729017; bh=1fxEhcneJjMBTg+E3RF7nPCfWEB16oCd3Fy8y169+Is=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=BaYVxtYA1ZzDBur1ph/BRpXxoWsAQ95eiSLYzHcb14KrUV1Li6/nhFrloCi10ccP5 yobCOdFLGV2rCZ8M1qn+OzY/cAb7lDzqMDT7mQa2OXMS/4p9GS5oum3HFbd4+QUjy/ LFQrdgXgVuKBRVFPA+AkSJtImY2j8fKgYKGojpKg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by sourceware.org (Postfix) with ESMTPS id E5C883857810 for ; Tue, 25 Oct 2022 20:16:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E5C883857810 Received: by mail-qt1-x835.google.com with SMTP id cr19so8451778qtb.0 for ; Tue, 25 Oct 2022 13:16:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1fxEhcneJjMBTg+E3RF7nPCfWEB16oCd3Fy8y169+Is=; b=HDVOY5L9tdUnV1REv3Q+n0gFtWp4DVG+oupx17VadqH/cYFNCsfxrxa543wWykNaBs hjp4mDBEk0w6apIFDNwY1NptE2KOr7jaxaOX/JaE1sE7R/k7erxtBiRD+DIpUdy6b6c5 ODuxxdz2Tdiw62jVr+xyLpBnw32tvBjQM4r0/QdL4vSPrvLHO31MWj2WXOcz2Ghgy70I OixnHWjN/AOnQTlsbzpwZzyW/hANQjELWdVimsuYOecsfHucbJW7xF46jywadlfRFGPE VHAv7hJNW3O6XgkyikssI3dTeY8LnxjEGueE2f+Ogm9tQzRhup/+sF6aXdTqRx44jOEL uq6Q== X-Gm-Message-State: ACrzQf2sITII/1GHdSO+pZBkoW2rApKbOXa7ctmAePq/cxt1UtXa5c7w 5+uwBfKwOBenz5STED+pWhm7+Mkdspwhsg== X-Received: by 2002:a05:622a:118a:b0:39c:f55e:2d70 with SMTP id m10-20020a05622a118a00b0039cf55e2d70mr33954113qtk.471.1666728972326; Tue, 25 Oct 2022 13:16:12 -0700 (PDT) Received: from ?IPV6:2601:19c:527f:bfd0::5? ([2601:19c:527f:bfd0::5]) by smtp.googlemail.com with ESMTPSA id h5-20020a05620a284500b006ecb3694163sm2623008qkp.95.2022.10.25.13.16.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Oct 2022 13:16:11 -0700 (PDT) Message-ID: Date: Tue, 25 Oct 2022 16:16:11 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Content-Language: en-US To: GCC Patches Subject: c++: Adjust synthetic template parm creation X-Spam-Status: No, score=-3039.0 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Nathan Sidwell via Gcc-patches From: Nathan Sidwell Reply-To: Nathan Sidwell Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747692047634959430?= X-GMAIL-MSGID: =?utf-8?q?1747692047634959430?= We intend to mark synthetic template parameters (coming from use of auto parms), as DECL_VIRTUAL_P. The API of process_template_parm is awkwardly confusing, and we were marking the previous template parm (unless this was the first parm). process_template_parm returns the list of parms, when most (all?) users really want the newly-added final node. That's a bigger change, so let's not do it right now. With this, we correctly mark such synthetic parms DECL_VIRTUAL_P. I fell over this trying to update template lambda mangling. The API of process_template_parm is somewhat awkaward, as it returns the whole list, and we end up doing a lot of tree_last calls, to get to the newly added node. I think all (or nearly all?) uses could be adapted to it returning the newly added list node, but I didn't want to go there right now. nathan From 43e654afeba484d75fbee080262a038c1da00ad5 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 25 Oct 2022 09:39:00 -0400 Subject: [PATCH] c++: Adjust synthetic template parm creation We intend to mark synthetic template parameters (coming from use of auto parms), as DECL_VIRTUAL_P. The API of process_template_parm is awkwardly confusing, and we were marking the previous template parm (unless this was the first parm). process_template_parm returns the list of parms, when most (all?) users really want the newly-added final node. That's a bigger change, so let's not do it right now. With this, we correctly mark such synthetic parms DECL_VIRTUAL_P. gcc/cp/ * parser.cc (synthesize_implicit_template_parm): Fix thinko about mark the new parm DECL_VIRTUAL_P. Avoid unneccessary tree_last call. --- gcc/cp/parser.cc | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index a39c5f0d24b..e685f190b3d 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -48996,12 +48996,11 @@ synthesize_implicit_template_parm (cp_parser *parser, tree constr) tree proto = constr ? DECL_INITIAL (constr) : NULL_TREE; tree synth_id = make_generic_type_name (); - tree synth_tmpl_parm; bool non_type = false; /* Synthesize the type template parameter. */ gcc_assert(!proto || TREE_CODE (proto) == TYPE_DECL); - synth_tmpl_parm = finish_template_type_parm (class_type_node, synth_id); + tree synth_tmpl_parm = finish_template_type_parm (class_type_node, synth_id); if (become_template) current_template_parms = tree_cons (size_int (current_template_depth + 1), @@ -49016,22 +49015,27 @@ synthesize_implicit_template_parm (cp_parser *parser, tree constr) node, /*non_type=*/non_type, /*param_pack=*/false); + // Process_template_parm returns the list of parms, and + // parser->implicit_template_parms holds the final node of the parm + // list. We really want to manipulate the newly appended element. + gcc_checking_assert (!parser->implicit_template_parms + || parser->implicit_template_parms == new_parm); + if (parser->implicit_template_parms) + new_parm = TREE_CHAIN (new_parm); + gcc_checking_assert (!TREE_CHAIN (new_parm)); + + // Record the last implicit parm node + parser->implicit_template_parms = new_parm; /* Mark the synthetic declaration "virtual". This is used when comparing template-heads to determine if whether an abbreviated function template is equivalent to an explicit template. - Note that DECL_ARTIFICIAL is used elsewhere for template parameters. */ + Note that DECL_ARTIFICIAL is used elsewhere for template + parameters. */ if (TREE_VALUE (new_parm) != error_mark_node) DECL_VIRTUAL_P (TREE_VALUE (new_parm)) = true; - // Chain the new parameter to the list of implicit parameters. - if (parser->implicit_template_parms) - parser->implicit_template_parms - = TREE_CHAIN (parser->implicit_template_parms); - else - parser->implicit_template_parms = new_parm; - tree new_decl = get_local_decls (); if (non_type) /* Return the TEMPLATE_PARM_INDEX, not the PARM_DECL. */ @@ -49059,7 +49063,7 @@ synthesize_implicit_template_parm (cp_parser *parser, tree constr) /* If the new parameter was constrained, we need to add that to the constraints in the template parameter list. */ - if (tree req = TEMPLATE_PARM_CONSTRAINTS (tree_last (new_parm))) + if (tree req = TEMPLATE_PARM_CONSTRAINTS (new_parm)) { tree reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms); reqs = combine_constraint_expressions (reqs, req); -- 2.37.3