From patchwork Sun Dec 3 23:24:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 81237 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 2C8CD3858410 for ; Sun, 3 Dec 2023 23:24:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 30D003858410 for ; Sun, 3 Dec 2023 23:24:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30D003858410 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 30D003858410 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=162.254.253.69 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701645858; cv=none; b=rVQ7ZUg8zf4qteo4n4jAVCEVlt9DnF/fzmnsexmAJVLpEeC7DHp9Fr6VKgwcFivADghR1ertQbiQQJCKYRto/K/VTtNqQVzza68xZop7SFt7DD93KBaLajZXtZwln0vbf2yFhP+6ZyVO8KZVQtUlVThJ6djh0FUm4ZbmSyHJN+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701645858; c=relaxed/simple; bh=JM+1pq6Adjc2xB6JsQhKbAbMlMFOxsr07i4fL2YdU0M=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Le+NFzI1vldv3yeEgkaDtISR2LUze6gBIZJh6Q18B9FINTHBsHVFZZXDuXU6Qf3YpU4PRKIWnQwElqHYlYqeAU8Uz/C/vtA10sUVZ1o/QWoQr2nCHrYjrHJORkAcjKlfJglw64ofHh2ohYMsxsEshpDN9WgN5tsrn+MoVw+7Hjg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=q6Z7j3AqnY9hshzguja8rg9uCj77t8P7QBi5zEf1Eng=; b=F4gxyTqfl2WudxDJor301ZFoPV An/Xg22LsBEWFRoj7qvWQOAT57RQN0uiUEzxC3TCeeidbB5laUxHhogMJ5M+0t1zItDb6N8AuTN0C 1WosAzW19mSmP9AjQE9IVPh3RvGJjiUwvVim14YlOIal/9L+MeE7sudrqWa4SwVoGoQ5xJR1zrJ+9 dYwbNfezC7qnBZyR1lhQZc3FO6L5rycc1SWFRtExpaOMWGx5EyKYBR+d51YaR/abLgVImWM0JIo1U 2l1j8E2AbfpJLMDBtrMYD0q6VlKl0mlQn0xTwTpP+ayj5bB4U7GO8ESdRgefJhGE9SJl8vNAToYIM 8pUmG4HA==; Received: from host109-153-232-220.range109-153.btcentralplus.com ([109.153.232.220]:49330 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1r9vot-000434-0o; Sun, 03 Dec 2023 18:24:15 -0500 From: "Roger Sayle" To: Cc: "'Richard Sandiford'" Subject: [PATCH] Workaround array_slice constructor portability issues (with older g++). Date: Sun, 3 Dec 2023 23:24:12 -0000 Message-ID: <006601da263f$d455aa30$7d00fe90$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdomP6iTlDTXN4tYRjWSa6TVA2CIZg== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MIME_QP_LONG_LINE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org The recent change to represent language and target attribute tables using vec.h's array_slice template class triggers an issue/bug in older g++ compilers, specifically the g++ 4.8.5 system compiler of older RedHat distributions. This exhibits as the following compilation errors during bootstrap: ../../gcc/gcc/c/c-lang.cc:55:2661: error: could not convert '(const scoped_attribute_specs* const*)(& c_objc_attribute_table)' from 'const scoped_attribute_specs* const*' to 'array_slice' struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; ../../gcc/gcc/c/c-decl.cc:4657:1: error: could not convert '(const attribute_spec*)(& std_attributes)' from 'const attribute_spec*' to 'array_slice' Here the issue is with constructors of the from: static const int table[] = { 1, 2, 3 }; array_slice t = table; Perhaps there's a fix possible in vec.h (an additional constructor?), but the patch below fixes this issue by using one of array_slice's constructors (that takes a size) explicitly, rather than rely on template resolution. In the example above this looks like: array_slice t (table, 3); or equivalently array_slice t = array_slice(table, 3); or equivalently array_slice t = array_slice(table, ARRAY_SIZE (table)); This patch has been tested on x86_64-pc-linux-gnu with make bootstrap, where these changes allow the bootstrap to complete. Ok for mainline? This fix might not by ideal, but it both draws attention to the problem and restores bootstrap whilst better approaches are investigated. For example, an ARRAY_SLICE(table) macro might be appropriate if there isn't an easy/portable template resolution solution. Thoughts? 2023-12-03 Roger Sayle gcc/c-family/ChangeLog * c-attribs.cc (c_common_gnu_attribute_table): Use an explicit array_slice constructor with an explicit size argument. (c_common_format_attribute_table): Likewise. gcc/c/ChangeLog * c-decl.cc (std_attribute_table): Use an explicit array_slice constructor with an explicit size argument. * c-objc-common.h (LANG_HOOKS_ATTRIBUTE_TABLE): Likewise. gcc/ChangeLog * config/i386/i386-options.cc (ix86_gnu_attribute_table): Use an explicit array_slice constructor with an explicit size argument. * config/i386/i386.cc (TARGET_ATTRIBUTE_TABLE): Likewise. gcc/cp/ChangeLog * cp-objcp-common.h (LANG_HOOKS_ATTRIBUTE_TABLE): Use an explicit array_slice constructor with an explicit size argument. * tree.cc (cxx_gnu_attribute_table): Likewise. (std_attribute_table): Likewise. gcc/lto/ChangeLog * lto-lang.cc (lto_gnu_attribute_table): Use an explicit array_slice constructor with an explicit size argument. (lto_format_attribute_table): Likewise. (LANG_HOOKS_ATTRIBUTE_TABLE): Likewise. Thanks in advance, Roger diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 45af074..af83588 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -584,7 +584,9 @@ const struct attribute_spec c_common_gnu_attributes[] = const struct scoped_attribute_specs c_common_gnu_attribute_table = { - "gnu", c_common_gnu_attributes + "gnu", + array_slice(c_common_gnu_attributes, + ARRAY_SIZE (c_common_gnu_attributes)) }; /* Give the specifications for the format attributes, used by C and all @@ -603,7 +605,9 @@ const struct attribute_spec c_common_format_attributes[] = const struct scoped_attribute_specs c_common_format_attribute_table = { - "gnu", c_common_format_attributes + "gnu", + array_slice(c_common_format_attributes, + ARRAY_SIZE (c_common_format_attributes)) }; /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 248d1bb..a6984b0 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -4653,7 +4653,8 @@ static const attribute_spec std_attributes[] = const scoped_attribute_specs std_attribute_table = { - nullptr, std_attributes + nullptr, array_slice(std_attributes, + ARRAY_SIZE (std_attributes)) }; /* Create the predefined scalar types of C, diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h index 426d938..021c651 100644 --- a/gcc/c/c-objc-common.h +++ b/gcc/c/c-objc-common.h @@ -83,7 +83,8 @@ static const scoped_attribute_specs *const c_objc_attribute_table[] = }; #undef LANG_HOOKS_ATTRIBUTE_TABLE -#define LANG_HOOKS_ATTRIBUTE_TABLE c_objc_attribute_table +#define LANG_HOOKS_ATTRIBUTE_TABLE \ +array_slice (c_objc_attribute_table, ARRAY_SIZE (c_objc_attribute_table)) #undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN #define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN c_dump_tree diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc index 8776592..50b3425 100644 --- a/gcc/config/i386/i386-options.cc +++ b/gcc/config/i386/i386-options.cc @@ -4171,7 +4171,9 @@ static const attribute_spec ix86_gnu_attributes[] = const scoped_attribute_specs ix86_gnu_attribute_table = { - "gnu", ix86_gnu_attributes + "gnu", + array_slice(ix86_gnu_attributes, + ARRAY_SIZE (ix86_gnu_attributes)) }; #include "gt-i386-options.h" diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 0f91ee7..400b7cb 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -25981,7 +25981,7 @@ static const scoped_attribute_specs *const ix86_attribute_table[] = #define TARGET_LEGITIMIZE_ADDRESS ix86_legitimize_address #undef TARGET_ATTRIBUTE_TABLE -#define TARGET_ATTRIBUTE_TABLE ix86_attribute_table +#define TARGET_ATTRIBUTE_TABLE array_slice(ix86_attribute_table, ARRAY_SIZE (ix86_attribute_table)) #undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_const_tree_true #if TARGET_DLLIMPORT_DECL_ATTRIBUTES diff --git a/gcc/cp/cp-objcp-common.h b/gcc/cp/cp-objcp-common.h index b53d11e..a8d12a5 100644 --- a/gcc/cp/cp-objcp-common.h +++ b/gcc/cp/cp-objcp-common.h @@ -132,7 +132,7 @@ static const scoped_attribute_specs *const cp_objcp_attribute_table[] = }; #undef LANG_HOOKS_ATTRIBUTE_TABLE -#define LANG_HOOKS_ATTRIBUTE_TABLE cp_objcp_attribute_table +#define LANG_HOOKS_ATTRIBUTE_TABLE array_slice (cp_objcp_attribute_table, ARRAY_SIZE (cp_objcp_attribute_table)) #undef LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P #define LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P cp_var_mod_type_p diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index e0b9d51..989f36b 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -5098,7 +5098,9 @@ static const attribute_spec cxx_gnu_attributes[] = const scoped_attribute_specs cxx_gnu_attribute_table = { - "gnu", cxx_gnu_attributes + "gnu", + array_slice (cxx_gnu_attributes, + ARRAY_SIZE (cxx_gnu_attributes)) }; /* Table of C++ standard attributes. */ @@ -5126,7 +5128,12 @@ static const attribute_spec std_attributes[] = handle_contract_attribute, NULL } }; -const scoped_attribute_specs std_attribute_table = { nullptr, std_attributes }; +const scoped_attribute_specs std_attribute_table = +{ + nullptr, + array_slice (std_attributes, + ARRAY_SIZE (std_attributes)) +}; /* Handle an "init_priority" attribute; arguments as in struct attribute_spec.handler. */ diff --git a/gcc/lto/lto-lang.cc b/gcc/lto/lto-lang.cc index 41de35a..67cea40 100644 --- a/gcc/lto/lto-lang.cc +++ b/gcc/lto/lto-lang.cc @@ -140,7 +140,9 @@ static const attribute_spec lto_gnu_attributes[] = static const scoped_attribute_specs lto_gnu_attribute_table = { - "gnu", lto_gnu_attributes + "gnu", + array_slice(lto_gnu_attributes, + ARRAY_SIZE (lto_gnu_attributes)) }; /* Give the specifications for the format attributes, used by C and all @@ -158,7 +160,9 @@ static const attribute_spec lto_format_attributes[] = static const scoped_attribute_specs lto_format_attribute_table = { - "gnu", lto_format_attributes + "gnu", + array_slice(lto_format_attributes, + ARRAY_SIZE (lto_format_attributes)) }; static const scoped_attribute_specs *const lto_attribute_table[] = @@ -1478,7 +1482,7 @@ static void lto_init_ts (void) /* Attribute hooks. */ #undef LANG_HOOKS_ATTRIBUTE_TABLE -#define LANG_HOOKS_ATTRIBUTE_TABLE lto_attribute_table +#define LANG_HOOKS_ATTRIBUTE_TABLE array_slice (lto_attribute_table, ARRAY_SIZE (lto_attribute_table)) #undef LANG_HOOKS_BEGIN_SECTION #define LANG_HOOKS_BEGIN_SECTION lto_obj_begin_section