From patchwork Wed Sep 28 20:44:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1512 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f2ce:0:0:0:0:0 with SMTP id d14csp362018wrp; Wed, 28 Sep 2022 13:45:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7yH33YUOeKtgiTGIvXGbnbIbqxHXhhuhBKDtBCHCykciAsXvokVJ+O2Z7BSs0BynxGcGjF X-Received: by 2002:a17:906:5a4c:b0:76f:3e98:b453 with SMTP id my12-20020a1709065a4c00b0076f3e98b453mr29138078ejc.509.1664397918584; Wed, 28 Sep 2022 13:45:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664397918; cv=none; d=google.com; s=arc-20160816; b=housjY68m+xSWDHxqibYlfHrT9W1bh+AJ+GvRmOPrRK5L/7gFhO9gd/Klgz/p3QNCt 8Co/yIC4Dug22KELHTOc37kSdVaqtq80uHTgslb3VCqBkrzLyx1sfcWUNj5AX6AY5Lf3 4X8tuNw2cqdj85W4Fj+WVyWem+OwM4yEiCp7uu0xT6kaDdZHUUZ4hc2eN8cIAQUk/Vxn Gd7Pxi9/AcJJdhMvSQmVnTnvKUS5yC5LtsGJQbPX+Bg0Faz09hPSeliXZHxTOak4cXXK kf5+Yi2TxeJDdcDh2vSbr/CWOeRDB9M/EUWmN+Nf9/YZqgJXYJ8MuLFELA+fQA7tt78t hl0Q== 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=4p1PX1sqYnOWx0DwjtZ08x7AdxRp54tUbCJctd3dnQM=; b=or0p8gcZeF4WFetvQmq3TlWvSC5Ats0Pn8GRpGDX4PKt4GQQniMv7E/gAKw1/U225S 5+b8GUfmf9+Z6t4JALFCmnAyjm98pP1M+H+FOzC5xdAJz3rqRutSJV9L+hiKkFBSWRQr rOvFuXKvgWxaxtQhbC3kStwFt7KEs6nyyKraumGcFu32Q3El4cFn+mnX/hAUTww495wt FznOUMuxSTpX1Vrx12WEI7YiQ/465smQiDTSlHQx6T/TPUd8MB/pr2VEG24ThpQNV3sI cvsa2mnnXS+Vj5ZD+e7X3sqi3mKyAH/FKqlHgn6mlbdYRbPEKFkKDgse4Fx8GCnBhLji QlAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=R7xfFYgT; 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 f15-20020a0564021e8f00b0045465c35632si6463524edf.255.2022.09.28.13.45.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 13:45:18 -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=R7xfFYgT; 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 4671D3858403 for ; Wed, 28 Sep 2022 20:45:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4671D3858403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664397917; bh=4p1PX1sqYnOWx0DwjtZ08x7AdxRp54tUbCJctd3dnQM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=R7xfFYgTpH4B7uWIrAluOb7iZlJ0bnKhsY3NX3kDh9SMmfzciaEn+GbhgkUsFdkoL xYA/F5gZK3iD2tTuCldw3iReDD/Sp1jx5miDxg/mjAT+FomVyjTuNQE2qh1GMKJ7c2 uuIEH0HQnWpGfCJcev46eR2W52jkZ2r+ywq/ZdmE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by sourceware.org (Postfix) with ESMTPS id E47533858D37 for ; Wed, 28 Sep 2022 20:44:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E47533858D37 Received: by mail-qk1-x72c.google.com with SMTP id d17so8612298qko.13 for ; Wed, 28 Sep 2022 13:44:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:sender:x-gm-message-state:from:to:cc:subject:date; bh=4p1PX1sqYnOWx0DwjtZ08x7AdxRp54tUbCJctd3dnQM=; b=Sy4kEYI+cmRO8sZAZFg+ShCYxmP0b4o3c3JEW2NXAAR+TzbnpH8XQJOxwNgGo1AtdF B9ux3qhlZJ4wvpZlhXN2wubsbgHMLpPnFUQXsq2yD0QtaR7KoXDSW+dQYn0Z9ywa64l0 vLSh35DjxRExgUlGokh8XJA+bhrHSsKooGOc7Ml3rJ2Kxvjp8PGe1iEURsMi9eVD7FyO 6wtwd6fafM9GJss6/ETE2aS9ynttXH21HGrrju5Urg2uBmKAKrgIGKXDcNO7pN0L3I24 lp//p7lXdw5ZCKN/iaI2DfRfSOtsQqn1/oHqZQ7vPfCqLUlJvrIUZWeOkc/nG3WvvXga IK9w== X-Gm-Message-State: ACrzQf2u0oOuqHCQuLzb/+Mj5qT1xJmPGF/CC2lLzv26VSUT6mDF0zX4 xAv6EI8LYxHnXGD8oEAxjZs= X-Received: by 2002:a05:620a:28d2:b0:6ce:66a7:c0c6 with SMTP id l18-20020a05620a28d200b006ce66a7c0c6mr22690307qkp.166.1664397873264; Wed, 28 Sep 2022 13:44:33 -0700 (PDT) Received: from ?IPV6:2620:10d:c0a8:11c9::1035? ([2620:10d:c091:480::d460]) by smtp.googlemail.com with ESMTPSA id bv21-20020a05622a0a1500b00342f8d4d0basm3774862qtb.43.2022.09.28.13.44.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Sep 2022 13:44:31 -0700 (PDT) Message-ID: Date: Wed, 28 Sep 2022 16:44:29 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Content-Language: en-US To: Patrick Palka , GCC Patches Subject: c++: Add DECL_NTTP_OBJECT_P lang flag X-Spam-Status: No, score=-3038.8 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?1745247711754815935?= X-GMAIL-MSGID: =?utf-8?q?1745247711754815935?= VAR_DECLs for NTTPs need to be handled specially by module streaming, in the same manner to type info decls. This reworks their handling to allow that work to drop in. We use DECL_LANG_FLAG_5 to indicate such decls (I didn't notice template_parm_object_p, which looks at the mangled name -- anyway a bit flag on the node is better, IMHO). We break apart the creation routine, so there's now an entry point the module machinery can use directly. nathan From 50888e70c984da9cd9676d3986f68222581884b3 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 28 Sep 2022 09:20:27 -0700 Subject: [PATCH] c++: Add DECL_NTTP_OBJECT_P lang flag VAR_DECLs for NTTPs need to be handled specially by module streaming, in the same manner to type info decls. This reworks their handling to allow that work to drop in. We use DECL_LANG_FLAG_5 to indicate such decls (I didn't notice template_parm_object_p, which looks at the mangled name -- anyway a bit flag on the node is better, IMHO). We break apart the creation routine, so there's now an entry point the module machinery can use directly. gcc/cp/ * cp-tree.h (DECL_NTTP_OBJECT_P): New. (template_parm_object_p): Delete. (build_template_parm_object): Declare. * cxx-pretty-print.cc (pp_cx_template_argument_list): Use DECL_NTTP_OBJECT_P. * error.cc (dump_simple_decl): Likewise. * mangle.cc (write_template_arg): Likewise. * pt.cc (template_parm_object_p): Delete. (create_template_parm_object): Separated out checking from ... (get_template_parm_object): ... this, new external entry point. --- gcc/cp/cp-tree.h | 7 ++++++- gcc/cp/cxx-pretty-print.cc | 2 +- gcc/cp/error.cc | 2 +- gcc/cp/mangle.cc | 2 +- gcc/cp/pt.cc | 35 +++++++++++++++++------------------ 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 19bbfbc557f..d0f1b18b015 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -518,6 +518,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; CALL_EXPR_REVERSE_ARGS (in CALL_EXPR, AGGR_INIT_EXPR) CONSTRUCTOR_PLACEHOLDER_BOUNDARY (in CONSTRUCTOR) OVL_EXPORT_P (in OVERLOAD) + DECL_NTTP_OBJECT_P (in VAR_DECL) 6: TYPE_MARKED_P (in _TYPE) DECL_NONTRIVIALLY_INITIALIZED_P (in VAR_DECL) RANGE_FOR_IVDEP (in RANGE_FOR_STMT) @@ -3548,6 +3549,10 @@ struct GTY(()) lang_decl { #define DECL_TINFO_P(NODE) \ TREE_LANG_FLAG_4 (TREE_CHECK2 (NODE,VAR_DECL,TYPE_DECL)) +/* true iff VAR_DECL node NODE is a NTTP object decl. */ +#define DECL_NTTP_OBJECT_P(NODE) \ + TREE_LANG_FLAG_5 (TREE_CHECK (NODE,VAR_DECL)) + /* 1 iff VAR_DECL node NODE is virtual table or VTT. We forward to DECL_VIRTUAL_P from the common code, as that has the semantics we need. But we want a more descriptive name. */ @@ -7414,7 +7419,7 @@ extern bool alias_type_or_template_p (tree); enum { nt_opaque = false, nt_transparent = true }; extern tree alias_template_specialization_p (const_tree, bool); extern tree dependent_alias_template_spec_p (const_tree, bool); -extern bool template_parm_object_p (const_tree); +extern tree get_template_parm_object (tree expr, tree mangle); extern tree tparm_object_argument (tree); extern bool explicit_class_specialization_p (tree); extern bool push_tinst_level (tree); diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc index e18143e39a9..bbd51bb562a 100644 --- a/gcc/cp/cxx-pretty-print.cc +++ b/gcc/cp/cxx-pretty-print.cc @@ -1956,7 +1956,7 @@ pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t) if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL && TYPE_P (DECL_TEMPLATE_RESULT (arg)))) pp->type_id (arg); - else if (template_parm_object_p (arg)) + else if (TREE_CODE (arg) == VAR_DECL && DECL_NTTP_OBJECT_P (arg)) pp->expression (DECL_INITIAL (arg)); else pp->expression (arg); diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index 0389f35d731..53904e3669d 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -1129,7 +1129,7 @@ dump_global_iord (cxx_pretty_printer *pp, tree t) static void dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags) { - if (template_parm_object_p (t)) + if (TREE_CODE (t) == VAR_DECL && DECL_NTTP_OBJECT_P (t)) return dump_expr (pp, DECL_INITIAL (t), flags); if (flags & TFF_DECL_SPECIFIERS) diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc index 00d283fff8c..1a455858827 100644 --- a/gcc/cp/mangle.cc +++ b/gcc/cp/mangle.cc @@ -3672,7 +3672,7 @@ write_template_arg (tree node) } } - if (template_parm_object_p (node)) + if (TREE_CODE (node) == VAR_DECL && DECL_NTTP_OBJECT_P (node)) /* We want to mangle the argument, not the var we stored it in. */ node = tparm_object_argument (node); diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 2d83dfd6954..c7adaef997d 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -7112,16 +7112,6 @@ unify_template_argument_mismatch (bool explain_p, tree parm, tree arg) return unify_invalid (explain_p); } -/* True if T is a C++20 template parameter object to store the argument for a - template parameter of class type. */ - -bool -template_parm_object_p (const_tree t) -{ - return (TREE_CODE (t) == VAR_DECL && DECL_ARTIFICIAL (t) && DECL_NAME (t) - && startswith (IDENTIFIER_POINTER (DECL_NAME (t)), "_ZTA")); -} - /* Subroutine of convert_nontype_argument, to check whether EXPR, as an argument for TYPE, points to an unsuitable object. @@ -7256,16 +7246,11 @@ invalid_tparm_referent_p (tree type, tree expr, tsubst_flags_t complain) } -/* The template arguments corresponding to template parameter objects of types - that contain pointers to members. */ - -static GTY(()) hash_map *tparm_obj_values; - /* Return a VAR_DECL for the C++20 template parameter object corresponding to template argument EXPR. */ static tree -get_template_parm_object (tree expr, tsubst_flags_t complain) +create_template_parm_object (tree expr, tsubst_flags_t complain) { if (TREE_CODE (expr) == TARGET_EXPR) expr = TARGET_EXPR_INITIAL (expr); @@ -7283,13 +7268,27 @@ get_template_parm_object (tree expr, tsubst_flags_t complain) /* This is no longer a compound literal. */ gcc_assert (!TREE_HAS_CONSTRUCTOR (expr)); - tree name = mangle_template_parm_object (expr); + return get_template_parm_object (expr, mangle_template_parm_object (expr)); +} + +/* The template arguments corresponding to template parameter objects of types + that contain pointers to members. */ + +static GTY(()) hash_map *tparm_obj_values; + +/* Find or build an nttp object for (already-validated) EXPR with name + NAME. */ + +tree +get_template_parm_object (tree expr, tree name) +{ tree decl = get_global_binding (name); if (decl) return decl; tree type = cp_build_qualified_type (TREE_TYPE (expr), TYPE_QUAL_CONST); decl = create_temporary_var (type); + DECL_NTTP_OBJECT_P (decl) = true; DECL_CONTEXT (decl) = NULL_TREE; TREE_STATIC (decl) = true; DECL_DECLARED_CONSTEXPR_P (decl) = true; @@ -7776,7 +7775,7 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) /* Replace the argument with a reference to the corresponding template parameter object. */ if (!val_dep_p) - expr = get_template_parm_object (expr, complain); + expr = create_template_parm_object (expr, complain); if (expr == error_mark_node) return NULL_TREE; } -- 2.30.2