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: 1756514 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ng+THGej; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pb7FZ3kGjz1yWs for ; Tue, 14 Mar 2023 07:15:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D5A33858421 for ; Mon, 13 Mar 2023 20:15:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D5A33858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678738541; bh=6vWRSz5YnTP2bWTqTR4B7kWiuBHn7oznHayYWR5DAVY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ng+THGejQa32RBnwaQujuGeHzYEeEGSbZeN0/3FVb3EtULGtL2L9/4Feyxj0r9sla CtsD/B8hRL57Egw+tKwz9uCUduLmXqmKQgUepLuPMYJkuMiZ+CBESqbUjaRHMVEgTY nXqhOGZkC3MaKidhEtyXX62VqcfTIAp+flsa/bCc= 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+incoming=patchwork.ozlabs.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. */