From patchwork Mon Mar 13 20:15:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 66319 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 409993858C2D for ; Mon, 13 Mar 2023 20:15:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 409993858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678738550; bh=6vWRSz5YnTP2bWTqTR4B7kWiuBHn7oznHayYWR5DAVY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=YF8E1ipRDIFTMlCScGZCk28OsRgscI9YmjGhndRljBW+yqbBcs6ymp2xl6c7vsRVu EmtF0lqXhDq5ts2KuBSHYU8ughyA/svggqAgisVQtkkWh6t/U/4cqHo73881Pji8RS EeE3v1XiyGvYZKobmOzN4wQCWt6Ib1mKxkcbosAU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 787613858D1E for ; Mon, 13 Mar 2023 20:15:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 787613858D1E Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-461-RafrcUIWMh6zNt6jyMaWAg-1; Mon, 13 Mar 2023 16:15:18 -0400 X-MC-Unique: RafrcUIWMh6zNt6jyMaWAg-1 Received: by mail-qk1-f200.google.com with SMTP id d10-20020a05620a240a00b0073baf1de8ebso7213713qkn.19 for ; Mon, 13 Mar 2023 13:15:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678738518; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6vWRSz5YnTP2bWTqTR4B7kWiuBHn7oznHayYWR5DAVY=; b=SWn8gT0cpdsizvRCyLFHgC9tJPso+3ot7egbfZB9hfSA9jJaAwi4HbhIVdMIK3wl9Y Gcywh4bctcmDkeyOugCr9bDkq8wQqCE7IFbCBcAtcJXs1C/mUnHyh17CWbN2fhA1n4Ke r+ueIZQVlK8x8Iv0ZJTEwmgk5gV6LuOvr2adJMLNISB3ailefXzCL8IFhCwAOu60gGtt sttWcNmLyACXEtT2qCkNcwGIssAncrmgZRbS4xAZT7p+oHwEQeZ2cdyPNGqFCRjvd3DV vlfoYMO46wiV4XxNXLC+Ou+K2R0QlU+fvpod1vwOklHFh+ucjIJzGEh6JwyyK3Fe4fjW ai0Q== X-Gm-Message-State: AO0yUKXAVGxRGpCeZNosuvTb9SVKt+RLGY4JvlAIcLiURiQzHEIfN63I b5WkVhjYRwnERNGNIXH8bOk12VkuEuvzbbX7AOjtAekYIxsOPOXqMiTIjyBhvH+nMnCYJFsYKe2 xvkBjFe98COKjvjoSMMVnNt0cUapjXKoy3ltHKI83v3RgC/Eas9dW0uXjG0WVquR1YuSzXrwx9Q == X-Received: by 2002:a05:622a:292:b0:3bf:c346:a743 with SMTP id z18-20020a05622a029200b003bfc346a743mr29729560qtw.39.1678738517970; Mon, 13 Mar 2023 13:15:17 -0700 (PDT) X-Google-Smtp-Source: AK7set91TSuMDwcvtM2A5fRiP9naLaVlKONqD0+l3xYZrjYn8TLZhR659v2qHemrfsZ4Ch5VctCfQQ== X-Received: by 2002:a05:622a:292:b0:3bf:c346:a743 with SMTP id z18-20020a05622a029200b003bfc346a743mr29729512qtw.39.1678738517467; Mon, 13 Mar 2023 13:15:17 -0700 (PDT) Received: from jason.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id dt5-20020a05620a478500b007456e020846sm383810qkb.13.2023.03.13.13.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 13:15:17 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Jakub Jelinek Subject: [PATCH RFA] tree: define tree_code_type in C++11/14 [PR108634] Date: Mon, 13 Mar 2023 16:15:12 -0400 Message-Id: <20230313201512.151814-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-pc-linux-gnu, OK for trunk? -- 8< -- The r13-6577 change to use tree_code_type_tmpl in earlier C++ dialects broke gdbhooks, which expects tree_code_type to always be available. I considered trying to make gdbhooks more robust, but it seemed simpler to define tree_code_type as a reference to the template. This still ends up with a definition of the reference in each translation unit, but that's allowed by the ODR because it always refers to the same entity, and is much smaller than having the whole table in each TU. PR plugins/108634 gcc/ChangeLog: * tree-core.h (tree_code_type, tree_code_length): Define even without inline variable support. * tree.h (TREE_CODE_CLASS, TREE_CODE_LENGTH): Only one definition. --- gcc/tree-core.h | 3 +++ gcc/tree.h | 10 ---------- 2 files changed, 3 insertions(+), 10 deletions(-) base-commit: c227508d06a63f9b8fede3fd88813accb447060e diff --git a/gcc/tree-core.h b/gcc/tree-core.h index fd2be57b78c..545dfd30114 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -2298,6 +2298,7 @@ struct tree_code_type_tmpl { template constexpr enum tree_code_class tree_code_type_tmpl::tree_code_type[]; +static constexpr auto &tree_code_type = tree_code_type_tmpl<0>::tree_code_type; #else constexpr inline enum tree_code_class tree_code_type[] = { #include "all-tree.def" @@ -2326,6 +2327,8 @@ struct tree_code_length_tmpl { template constexpr unsigned char tree_code_length_tmpl::tree_code_length[]; +static constexpr auto &tree_code_length += tree_code_length_tmpl<0>::tree_code_length; #else constexpr inline unsigned char tree_code_length[] = { #include "all-tree.def" diff --git a/gcc/tree.h b/gcc/tree.h index 91375f9652f..92ac0e6a214 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -177,12 +177,7 @@ code_helper::is_builtin_fn () const #define TREE_CODE_CLASS_STRING(CLASS)\ tree_code_class_strings[(int) (CLASS)] -#if __cpp_inline_variables < 201606L -#define TREE_CODE_CLASS(CODE) \ - tree_code_type_tmpl <0>::tree_code_type[(int) (CODE)] -#else #define TREE_CODE_CLASS(CODE) tree_code_type[(int) (CODE)] -#endif /* Nonzero if NODE represents an exceptional code. */ @@ -276,12 +271,7 @@ code_helper::is_builtin_fn () const #define EXPR_P(NODE) IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (NODE))) -#if __cpp_inline_variables < 201606L -#define TREE_CODE_LENGTH(CODE) \ - tree_code_length_tmpl <0>::tree_code_length[(int) (CODE)] -#else #define TREE_CODE_LENGTH(CODE) tree_code_length[(int) (CODE)] -#endif /* Helper macros for math builtins. */