public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Workaround array_slice constructor portability issues (with older g++).
@ 2023-12-03 23:24 Roger Sayle
  2023-12-04 10:41 ` Richard Sandiford
  0 siblings, 1 reply; 4+ messages in thread
From: Roger Sayle @ 2023-12-03 23:24 UTC (permalink / raw)
  To: gcc-patches; +Cc: 'Richard Sandiford'

[-- Attachment #1: Type: text/plain, Size: 2963 bytes --]


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<const
scoped_attribute_specs* const>'
 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<const attribute_spec>'

Here the issue is with constructors of the from:

static const int table[] = { 1, 2, 3 };
array_slice<int> 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<int> t (table, 3);

or equivalently

array_slice<int> t = array_slice<int>(table, 3);

or equivalently

array_slice<int> t = array_slice<int>(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  <roger@nextmovesoftware.com>

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
--


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 6064 bytes --]

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<const attribute_spec>(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<const attribute_spec>(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<const attribute_spec>(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<const scoped_attribute_specs* const> (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<const attribute_spec>(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<const scoped_attribute_specs* const>(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<const scoped_attribute_specs* const> (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<const attribute_spec> (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<const attribute_spec> (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<const attribute_spec>(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<const attribute_spec>(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<const scoped_attribute_specs* const> (lto_attribute_table, ARRAY_SIZE (lto_attribute_table))
 
 #undef LANG_HOOKS_BEGIN_SECTION
 #define LANG_HOOKS_BEGIN_SECTION lto_obj_begin_section

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Workaround array_slice constructor portability issues (with older g++).
  2023-12-03 23:24 [PATCH] Workaround array_slice constructor portability issues (with older g++) Roger Sayle
@ 2023-12-04 10:41 ` Richard Sandiford
  2023-12-04 13:19   ` [PATCH] Restore build with GCC 4.8 to GCC 5 (was Re: [PATCH] Workaround array_slice constructor portability issues (with older g++).) Richard Sandiford
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Sandiford @ 2023-12-04 10:41 UTC (permalink / raw)
  To: Roger Sayle; +Cc: gcc-patches

"Roger Sayle" <roger@nextmovesoftware.com> writes:
> 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<const
> scoped_attribute_specs* const>'
>  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<const attribute_spec>'
>
> Here the issue is with constructors of the from:
>
> static const int table[] = { 1, 2, 3 };
> array_slice<int> t = table;

It's array_slice<const int> rather than array_slice<int>.  The above
would be invalid even with functioning compilers.

> 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<int> t (table, 3);
>
> or equivalently
>
> array_slice<int> t = array_slice<int>(table, 3);
>
> or equivalently
>
> array_slice<int> t = array_slice<int>(table, ARRAY_SIZE (table));

Taking c-decl.cc as an arbitrary example, it seems to be enough to change:

const scoped_attribute_specs std_attribute_table =
{
  nullptr, std_attributes
};

to:

const scoped_attribute_specs std_attribute_table =
{
  nullptr, { std_attributes }
};

which seems less ugly than the explicit constructors.

But if we're going to do this, we should do it across the board,
not just for x86.

I think it's getting a bit ridiculous though.  Let's just accept
that 4.8.5 is not a fully functioning C++11 compiler and move on.
People who are still using that as their host compiler will need
to upgrade soon anyway, so we're just putting off the inevitable.
It's unlikely that these workarounds that we keep adding will ever
fully be removed.

Thanks,
Richard

> 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  <roger@nextmovesoftware.com>
>
> 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
> --

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] Restore build with GCC 4.8 to GCC 5 (was Re: [PATCH] Workaround array_slice constructor portability issues (with older g++).)
  2023-12-04 10:41 ` Richard Sandiford
@ 2023-12-04 13:19   ` Richard Sandiford
  2023-12-05 15:02     ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Sandiford @ 2023-12-04 13:19 UTC (permalink / raw)
  To: Roger Sayle; +Cc: gcc-patches

Richard Sandiford <richard.sandiford@arm.com> writes:
> "Roger Sayle" <roger@nextmovesoftware.com> writes:
>> 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<const
>> scoped_attribute_specs* const>'
>>  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<const attribute_spec>'
>>
>> Here the issue is with constructors of the from:
>>
>> static const int table[] = { 1, 2, 3 };
>> array_slice<int> t = table;
>
> It's array_slice<const int> rather than array_slice<int>.  The above
> would be invalid even with functioning compilers.
>
>> 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<int> t (table, 3);
>>
>> or equivalently
>>
>> array_slice<int> t = array_slice<int>(table, 3);
>>
>> or equivalently
>>
>> array_slice<int> t = array_slice<int>(table, ARRAY_SIZE (table));
>
> Taking c-decl.cc as an arbitrary example, it seems to be enough to change:
>
> const scoped_attribute_specs std_attribute_table =
> {
>   nullptr, std_attributes
> };
>
> to:
>
> const scoped_attribute_specs std_attribute_table =
> {
>   nullptr, { std_attributes }
> };
>
> which seems less ugly than the explicit constructors.
>
> But if we're going to do this, we should do it across the board,
> not just for x86.

Here's an attempt to do that.  Tested so far by building
aarch64-linux-gnu (which has target attributes) and frv-elf
(which doesn't) with GCC 4.8.

OK if further testing passes?

Richard

---

GCC 5 and earlier applied array-to-pointer decay too early,
which affected the new attribute namespace code.  A reduced
example of the construct that the attribute code uses is:

    struct S { template<__SIZE_TYPE__ N> S(int (&)[N]); };
    struct T { int a; S b; };
    int a[] = { 1 };
    T t = { 1, a };

This was fixed by f85e1317f8ea933f5c615680353bd646f480f7d3
(PR 16333 et al).

This patch tries to add a minimally-invasive workaround.

gcc/ada/
	* gcc-interface/utils.cc (gnat_internal_attribute_table): Add extra
	braces to work around PR 16333 in older compilers.

gcc/
	* attribs.cc (handle_ignored_attributes_option): Add extra
	braces to work around PR 16333 in older compilers.
	* config/arm/arm.cc (arm_gnu_attribute_table): Likewise.
	* config/i386/i386-options.cc (ix86_gnu_attribute_table): Likewise.
	* config/ia64/ia64.cc (ia64_gnu_attribute_table): Likewise.
	* config/rs6000/rs6000.cc (rs6000_gnu_attribute_table): Likewise.
	* target-def.h (TARGET_GNU_ATTRIBUTES): Likewise.
	* genhooks.cc (emit_init_macros): Likewise, when emitting the
	instantiation of TARGET_ATTRIBUTE_TABLE.
	* langhooks-def.h (LANG_HOOKS_INITIALIZER): Likewise, when
	instantiating LANG_HOOKS_ATTRIBUTE_TABLE.
	(LANG_HOOKS_ATTRIBUTE_TABLE): Define to be empty by default.
	* target.def (attribute_table): Likewise.

gcc/c-family/
	* c-attribs.cc (c_common_gnu_attribute_table): Add extra
	braces to work around PR 16333 in older compilers.

gcc/c/
	* c-decl.cc (std_attribute_table): Add extra braces to work
	around PR 16333 in older compilers.

gcc/cp/
	* tree.cc (cxx_gnu_attribute_table): Add extra braces to work
	around PR 16333 in older compilers.

gcc/d/
	* d-attribs.cc (d_langhook_common_attribute_table): Add extra braces
	to work around PR 16333 in older compilers.
	(d_langhook_gnu_attribute_table): Likewise.

gcc/fortran/
	* f95-lang.cc (gfc_gnu_attribute_table): Add extra braces to work
	around PR 16333 in older compilers.

gcc/jit/
	* dummy-frontend.cc (jit_gnu_attribute_table): Add extra braces
	to work around PR 16333 in older compilers.
	(jit_format_attribute_table): Likewise.

gcc/lto/
	* lto-lang.cc (lto_gnu_attribute_table): Add extra braces to work
	around PR 16333 in older compilers.
	(lto_format_attribute_table): Likewise.
---
 gcc/ada/gcc-interface/utils.cc  | 2 +-
 gcc/attribs.cc                  | 2 +-
 gcc/c-family/c-attribs.cc       | 4 ++--
 gcc/c/c-decl.cc                 | 2 +-
 gcc/config/arm/arm.cc           | 2 +-
 gcc/config/i386/i386-options.cc | 2 +-
 gcc/config/ia64/ia64.cc         | 2 +-
 gcc/config/rs6000/rs6000.cc     | 2 +-
 gcc/cp/tree.cc                  | 7 +++++--
 gcc/d/d-attribs.cc              | 4 ++--
 gcc/fortran/f95-lang.cc         | 2 +-
 gcc/genhooks.cc                 | 7 ++++++-
 gcc/jit/dummy-frontend.cc       | 4 ++--
 gcc/langhooks-def.h             | 4 ++--
 gcc/lto/lto-lang.cc             | 4 ++--
 gcc/target-def.h                | 2 +-
 gcc/target.def                  | 2 +-
 17 files changed, 31 insertions(+), 23 deletions(-)

diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc
index f46454d6545..6629d3f9b18 100644
--- a/gcc/ada/gcc-interface/utils.cc
+++ b/gcc/ada/gcc-interface/utils.cc
@@ -221,7 +221,7 @@ static const attribute_spec gnat_internal_attributes[] =
 
 const scoped_attribute_specs gnat_internal_attribute_table =
 {
-  "gnu", gnat_internal_attributes
+  "gnu", { gnat_internal_attributes }
 };
 
 /* Associates a GNAT tree node to a GCC tree node. It is used in
diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index eff99002fbb..1e6369a47fe 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -302,7 +302,7 @@ handle_ignored_attributes_option (vec<char *> *v)
 	  attrs = { table, 1 };
 	}
       const scoped_attribute_specs scoped_specs = {
-	IDENTIFIER_POINTER (vendor_id), attrs
+	IDENTIFIER_POINTER (vendor_id), { attrs }
       };
       register_scoped_attributes (scoped_specs, attrs.empty ());
     }
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index 45af07453ea..859dcf255ba 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -584,7 +584,7 @@ const struct attribute_spec c_common_gnu_attributes[] =
 
 const struct scoped_attribute_specs c_common_gnu_attribute_table =
 {
-  "gnu", c_common_gnu_attributes
+  "gnu", { c_common_gnu_attributes }
 };
 
 /* Give the specifications for the format attributes, used by C and all
@@ -603,7 +603,7 @@ const struct attribute_spec c_common_format_attributes[] =
 
 const struct scoped_attribute_specs c_common_format_attribute_table =
 {
-  "gnu", c_common_format_attributes
+  "gnu", { 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 248d1bb3206..92c83e1bf10 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -4653,7 +4653,7 @@ static const attribute_spec std_attributes[] =
 
 const scoped_attribute_specs std_attribute_table =
 {
-  nullptr, std_attributes
+  nullptr, { std_attributes }
 };
 
 /* Create the predefined scalar types of C,
diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index 5cb35e8d061..da5cda225f1 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -385,7 +385,7 @@ static const attribute_spec arm_gnu_attributes[] =
 
 static const scoped_attribute_specs arm_gnu_attribute_table =
 {
-  "gnu", arm_gnu_attributes
+  "gnu", { arm_gnu_attributes }
 };
 
 static const scoped_attribute_specs *const arm_attribute_table[] =
diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
index 877659229d2..f86ad332aad 100644
--- a/gcc/config/i386/i386-options.cc
+++ b/gcc/config/i386/i386-options.cc
@@ -4171,7 +4171,7 @@ static const attribute_spec ix86_gnu_attributes[] =
 
 const scoped_attribute_specs ix86_gnu_attribute_table =
 {
-  "gnu", ix86_gnu_attributes
+  "gnu", { ix86_gnu_attributes }
 };
 
 #include "gt-i386-options.h"
diff --git a/gcc/config/ia64/ia64.cc b/gcc/config/ia64/ia64.cc
index f7766c25622..ac566efcf19 100644
--- a/gcc/config/ia64/ia64.cc
+++ b/gcc/config/ia64/ia64.cc
@@ -375,7 +375,7 @@ static const attribute_spec ia64_gnu_attributes[] =
 
 static const scoped_attribute_specs ia64_gnu_attribute_table =
 {
-  "gnu", ia64_gnu_attributes
+  "gnu", { ia64_gnu_attributes }
 };
 
 static const scoped_attribute_specs *const ia64_attribute_table[] =
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 5386470f6f8..3801afe2c95 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -1276,7 +1276,7 @@ static const attribute_spec rs6000_gnu_attributes[] =
 
 static const scoped_attribute_specs rs6000_gnu_attribute_table =
 {
-  "gnu", rs6000_gnu_attributes
+  "gnu", { rs6000_gnu_attributes }
 };
 
 static const scoped_attribute_specs *const rs6000_attribute_table[] =
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index e0b9d512adc..da4d5c51f07 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -5098,7 +5098,7 @@ static const attribute_spec cxx_gnu_attributes[] =
 
 const scoped_attribute_specs cxx_gnu_attribute_table =
 {
-  "gnu", cxx_gnu_attributes
+  "gnu", { cxx_gnu_attributes }
 };
 
 /* Table of C++ standard attributes.  */
@@ -5126,7 +5126,10 @@ 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, { std_attributes }
+};
 
 /* Handle an "init_priority" attribute; arguments as in
    struct attribute_spec.handler.  */
diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc
index f6411058072..3b69c530c1d 100644
--- a/gcc/d/d-attribs.cc
+++ b/gcc/d/d-attribs.cc
@@ -194,7 +194,7 @@ static const attribute_spec d_langhook_common_attributes[] =
 
 const scoped_attribute_specs d_langhook_common_attribute_table =
 {
-  "gnu", d_langhook_common_attributes
+  "gnu", { d_langhook_common_attributes }
 };
 
 /* Table of D language attributes exposed by `gcc.attribute' UDAs.  */
@@ -246,7 +246,7 @@ static const attribute_spec d_langhook_gnu_attributes[] =
 
 const scoped_attribute_specs d_langhook_gnu_attribute_table =
 {
-  "gnu", d_langhook_gnu_attributes
+  "gnu", { d_langhook_gnu_attributes }
 };
 
 /* Insert the type attribute ATTRNAME with value VALUE into TYPE.
diff --git a/gcc/fortran/f95-lang.cc b/gcc/fortran/f95-lang.cc
index 99dd76226a2..32fddcde957 100644
--- a/gcc/fortran/f95-lang.cc
+++ b/gcc/fortran/f95-lang.cc
@@ -102,7 +102,7 @@ static const attribute_spec gfc_gnu_attributes[] =
 
 static const scoped_attribute_specs gfc_gnu_attribute_table =
 {
-  "gnu", gfc_gnu_attributes
+  "gnu", { gfc_gnu_attributes }
 };
 
 static const scoped_attribute_specs *const gfc_attribute_table[] =
diff --git a/gcc/genhooks.cc b/gcc/genhooks.cc
index 49414eca531..135c523bd00 100644
--- a/gcc/genhooks.cc
+++ b/gcc/genhooks.cc
@@ -304,7 +304,12 @@ emit_init_macros (const char *docname)
 		      name, name, hook_array[i].init);
 	    }
 	  if (nest == print_nest)
-	    printf ("    %s, \\\n", name);
+	    {
+	      if (strcmp (name, "TARGET_ATTRIBUTE_TABLE") == 0)
+		printf ("    { %s }, \\\n", name);
+	      else
+		printf ("    %s, \\\n", name);
+	    }
 	}
     }
 }
diff --git a/gcc/jit/dummy-frontend.cc b/gcc/jit/dummy-frontend.cc
index 61cc0e1ae66..1ea6ad382d8 100644
--- a/gcc/jit/dummy-frontend.cc
+++ b/gcc/jit/dummy-frontend.cc
@@ -133,7 +133,7 @@ static const attribute_spec jit_gnu_attributes[] =
 
 static const scoped_attribute_specs jit_gnu_attribute_table =
 {
-  "gnu", jit_gnu_attributes
+  "gnu", { jit_gnu_attributes }
 };
 
 /* Give the specifications for the format attributes, used by C and all
@@ -151,7 +151,7 @@ static const attribute_spec jit_format_attributes[] =
 
 static const scoped_attribute_specs jit_format_attribute_table =
 {
-  "gnu", jit_format_attributes
+  "gnu", { jit_format_attributes }
 };
 
 static const scoped_attribute_specs *const jit_attribute_table[] =
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index c9cb65759c2..042fd0174e3 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -153,7 +153,7 @@ extern const char *lhd_get_sarif_source_language (const char *);
 #define LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE lhd_get_sarif_source_language
 
 /* Attribute hooks.  */
-#define LANG_HOOKS_ATTRIBUTE_TABLE		{}
+#define LANG_HOOKS_ATTRIBUTE_TABLE
 
 /* Tree inlining hooks.  */
 #define LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P \
@@ -364,7 +364,7 @@ extern void lhd_end_section (void);
   LANG_HOOKS_TYPES_COMPATIBLE_P, \
   LANG_HOOKS_PRINT_ERROR_FUNCTION, \
   LANG_HOOKS_TO_TARGET_CHARSET, \
-  LANG_HOOKS_ATTRIBUTE_TABLE, \
+  { LANG_HOOKS_ATTRIBUTE_TABLE }, \
   LANG_HOOKS_TREE_INLINING_INITIALIZER, \
   LANG_HOOKS_TREE_DUMP_INITIALIZER, \
   LANG_HOOKS_DECLS, \
diff --git a/gcc/lto/lto-lang.cc b/gcc/lto/lto-lang.cc
index 41de35a9ff6..62aaa9b7d10 100644
--- a/gcc/lto/lto-lang.cc
+++ b/gcc/lto/lto-lang.cc
@@ -140,7 +140,7 @@ static const attribute_spec lto_gnu_attributes[] =
 
 static const scoped_attribute_specs lto_gnu_attribute_table =
 {
-  "gnu", lto_gnu_attributes
+  "gnu", { lto_gnu_attributes }
 };
 
 /* Give the specifications for the format attributes, used by C and all
@@ -158,7 +158,7 @@ static const attribute_spec lto_format_attributes[] =
 
 static const scoped_attribute_specs lto_format_attribute_table =
 {
-  "gnu", lto_format_attributes
+  "gnu", { lto_format_attributes }
 };
 
 static const scoped_attribute_specs *const lto_attribute_table[] =
diff --git a/gcc/target-def.h b/gcc/target-def.h
index d03b039ab24..79fe8e28e7e 100644
--- a/gcc/target-def.h
+++ b/gcc/target-def.h
@@ -129,7 +129,7 @@
 
 #define TARGET_GNU_ATTRIBUTES(NAME, ...) \
   static const attribute_spec NAME##_2[] = __VA_ARGS__; \
-  static const scoped_attribute_specs NAME##_1 = { "gnu", NAME##_2 }; \
+  static const scoped_attribute_specs NAME##_1 = { "gnu", { NAME##_2 } }; \
   static const scoped_attribute_specs *const NAME[] = { &NAME##_1 }
 
 #include "target-hooks-def.h"
diff --git a/gcc/target.def b/gcc/target.def
index c6562ed40ac..2c85be235e4 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -2247,7 +2247,7 @@ TARGET_GNU_ATTRIBUTES (@var{cpu_attribute_table}, @{\n\
   @{ \"@var{attributen}\", @dots{} @},\n\
 @});\n\
 @end smallexample",
- array_slice<const struct scoped_attribute_specs *const>, {})
+ array_slice<const struct scoped_attribute_specs *const>,)
 
 /* Return true iff attribute NAME expects a plain identifier as its first
    argument.  */
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Restore build with GCC 4.8 to GCC 5 (was Re: [PATCH] Workaround array_slice constructor portability issues (with older g++).)
  2023-12-04 13:19   ` [PATCH] Restore build with GCC 4.8 to GCC 5 (was Re: [PATCH] Workaround array_slice constructor portability issues (with older g++).) Richard Sandiford
@ 2023-12-05 15:02     ` Jakub Jelinek
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2023-12-05 15:02 UTC (permalink / raw)
  To: Roger Sayle, gcc-patches, richard.sandiford

On Mon, Dec 04, 2023 at 01:19:21PM +0000, Richard Sandiford wrote:
> >> (that takes a size) explicitly, rather than rely on template resolution.
> >> In the example above this looks like:
> >>
> >> array_slice<int> t (table, 3);
> >>
> >> or equivalently
> >>
> >> array_slice<int> t = array_slice<int>(table, 3);
> >>
> >> or equivalently
> >>
> >> array_slice<int> t = array_slice<int>(table, ARRAY_SIZE (table));
> >
> > Taking c-decl.cc as an arbitrary example, it seems to be enough to change:
> >
> > const scoped_attribute_specs std_attribute_table =
> > {
> >   nullptr, std_attributes
> > };
> >
> > to:
> >
> > const scoped_attribute_specs std_attribute_table =
> > {
> >   nullptr, { std_attributes }
> > };
> >
> > which seems less ugly than the explicit constructors.
> >
> > But if we're going to do this, we should do it across the board,
> > not just for x86.
> 
> Here's an attempt to do that.  Tested so far by building
> aarch64-linux-gnu (which has target attributes) and frv-elf
> (which doesn't) with GCC 4.8.
> 
> OK if further testing passes?
> 
> Richard
> 
> ---
> 
> GCC 5 and earlier applied array-to-pointer decay too early,
> which affected the new attribute namespace code.  A reduced
> example of the construct that the attribute code uses is:
> 
>     struct S { template<__SIZE_TYPE__ N> S(int (&)[N]); };
>     struct T { int a; S b; };
>     int a[] = { 1 };
>     T t = { 1, a };
> 
> This was fixed by f85e1317f8ea933f5c615680353bd646f480f7d3
> (PR 16333 et al).
> 
> This patch tries to add a minimally-invasive workaround.
> 
> gcc/ada/
> 	* gcc-interface/utils.cc (gnat_internal_attribute_table): Add extra
> 	braces to work around PR 16333 in older compilers.
> 
> gcc/
> 	* attribs.cc (handle_ignored_attributes_option): Add extra
> 	braces to work around PR 16333 in older compilers.
> 	* config/arm/arm.cc (arm_gnu_attribute_table): Likewise.
> 	* config/i386/i386-options.cc (ix86_gnu_attribute_table): Likewise.
> 	* config/ia64/ia64.cc (ia64_gnu_attribute_table): Likewise.
> 	* config/rs6000/rs6000.cc (rs6000_gnu_attribute_table): Likewise.
> 	* target-def.h (TARGET_GNU_ATTRIBUTES): Likewise.
> 	* genhooks.cc (emit_init_macros): Likewise, when emitting the
> 	instantiation of TARGET_ATTRIBUTE_TABLE.
> 	* langhooks-def.h (LANG_HOOKS_INITIALIZER): Likewise, when
> 	instantiating LANG_HOOKS_ATTRIBUTE_TABLE.
> 	(LANG_HOOKS_ATTRIBUTE_TABLE): Define to be empty by default.
> 	* target.def (attribute_table): Likewise.
> 
> gcc/c-family/
> 	* c-attribs.cc (c_common_gnu_attribute_table): Add extra
> 	braces to work around PR 16333 in older compilers.
> 
> gcc/c/
> 	* c-decl.cc (std_attribute_table): Add extra braces to work
> 	around PR 16333 in older compilers.
> 
> gcc/cp/
> 	* tree.cc (cxx_gnu_attribute_table): Add extra braces to work
> 	around PR 16333 in older compilers.
> 
> gcc/d/
> 	* d-attribs.cc (d_langhook_common_attribute_table): Add extra braces
> 	to work around PR 16333 in older compilers.
> 	(d_langhook_gnu_attribute_table): Likewise.
> 
> gcc/fortran/
> 	* f95-lang.cc (gfc_gnu_attribute_table): Add extra braces to work
> 	around PR 16333 in older compilers.
> 
> gcc/jit/
> 	* dummy-frontend.cc (jit_gnu_attribute_table): Add extra braces
> 	to work around PR 16333 in older compilers.
> 	(jit_format_attribute_table): Likewise.
> 
> gcc/lto/
> 	* lto-lang.cc (lto_gnu_attribute_table): Add extra braces to work
> 	around PR 16333 in older compilers.
> 	(lto_format_attribute_table): Likewise.

LGTM.

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-05 15:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-03 23:24 [PATCH] Workaround array_slice constructor portability issues (with older g++) Roger Sayle
2023-12-04 10:41 ` Richard Sandiford
2023-12-04 13:19   ` [PATCH] Restore build with GCC 4.8 to GCC 5 (was Re: [PATCH] Workaround array_slice constructor portability issues (with older g++).) Richard Sandiford
2023-12-05 15:02     ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).