[2/3] opcodes: fix -std=gnu23 compatibility wrt static_assert

Message ID 0bc9bfda425cb174ea8cd3822aa206dfba3b1ff0.1731738744.git.sam@gentoo.org
State New
Headers
Series C23 fixes |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 fail Patch failed to apply

Commit Message

Sam James Nov. 16, 2024, 6:32 a.m. UTC
  static_assert is declared in C23 so we can't reuse that identifier:
* Define our own static_assert conditionally;

* Rename "static assert" hacks to _N as we do already in some places
  to avoid a conflict.

ChangeLog:
	PR ld/32372

        * opcodes/i386-gen.c (static_assert): Define conditionally.
        * opcodes/mips-formats.h (MAPPED_INT): Rename identifier.
        (MAPPED_REG): Rename identifier.
        (OPTIONAL_MAPPED_REG): Rename identifier.
        * opcodes/s390-opc.c (static_assert): Define conditionally.
---
 opcodes/i386-gen.c     | 2 ++
 opcodes/mips-formats.h | 6 +++---
 opcodes/s390-opc.c     | 2 ++
 3 files changed, 7 insertions(+), 3 deletions(-)
  

Comments

H.J. Lu Nov. 16, 2024, 7:03 a.m. UTC | #1
On Sat, Nov 16, 2024 at 2:33 PM Sam James <sam@gentoo.org> wrote:
>
> static_assert is declared in C23 so we can't reuse that identifier:
> * Define our own static_assert conditionally;
>
> * Rename "static assert" hacks to _N as we do already in some places
>   to avoid a conflict.
>
> ChangeLog:
>         PR ld/32372
>
>         * opcodes/i386-gen.c (static_assert): Define conditionally.
>         * opcodes/mips-formats.h (MAPPED_INT): Rename identifier.
>         (MAPPED_REG): Rename identifier.
>         (OPTIONAL_MAPPED_REG): Rename identifier.
>         * opcodes/s390-opc.c (static_assert): Define conditionally.

No opcodes/ prefix.

> ---
>  opcodes/i386-gen.c     | 2 ++
>  opcodes/mips-formats.h | 6 +++---
>  opcodes/s390-opc.c     | 2 ++
>  3 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/opcodes/i386-gen.c b/opcodes/i386-gen.c
> index 053b66675c5..7ee8a30310c 100644
> --- a/opcodes/i386-gen.c
> +++ b/opcodes/i386-gen.c
> @@ -30,7 +30,9 @@
>
>  /* Build-time checks are preferrable over runtime ones.  Use this construct
>     in preference where possible.  */
> +#ifndef static_assert
>  #define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
> +#endif
>
>  static const char *program_name = NULL;
>  static int debug = 0;
> diff --git a/opcodes/mips-formats.h b/opcodes/mips-formats.h
> index 90df7100803..c4dec6352bf 100644
> --- a/opcodes/mips-formats.h
> +++ b/opcodes/mips-formats.h
> @@ -49,7 +49,7 @@
>  #define MAPPED_INT(SIZE, LSB, MAP, PRINT_HEX) \
>    { \
>      typedef char ATTRIBUTE_UNUSED \
> -      static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
> +      static_assert_3[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
>      static const struct mips_mapped_int_operand op = { \
>        { OP_MAPPED_INT, SIZE, LSB }, MAP, PRINT_HEX \
>      }; \
> @@ -83,7 +83,7 @@
>  #define MAPPED_REG(SIZE, LSB, BANK, MAP) \
>    { \
>      typedef char ATTRIBUTE_UNUSED \
> -      static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
> +      static_assert_4[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
>      static const struct mips_reg_operand op = { \
>        { OP_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
>      }; \
> @@ -93,7 +93,7 @@
>  #define OPTIONAL_MAPPED_REG(SIZE, LSB, BANK, MAP) \
>    { \
>      typedef char ATTRIBUTE_UNUSED \
> -      static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
> +      static_assert_5[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
>      static const struct mips_reg_operand op = { \
>        { OP_OPTIONAL_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
>      }; \
> diff --git a/opcodes/s390-opc.c b/opcodes/s390-opc.c
> index 9d9f0973e55..49efd714157 100644
> --- a/opcodes/s390-opc.c
> +++ b/opcodes/s390-opc.c
> @@ -36,7 +36,9 @@
>
>  /* Build-time checks are preferrable over runtime ones.  Use this construct
>     in preference where possible.  */
> +#ifndef static_assert
>  #define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
> +#endif
>
>  #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
>
> --
> 2.47.0
>
  
Jens Remus Nov. 18, 2024, 9:39 a.m. UTC | #2
On 16.11.2024 07:32, Sam James wrote:
> static_assert is declared in C23 so we can't reuse that identifier:
> * Define our own static_assert conditionally;

...

> diff --git a/opcodes/s390-opc.c b/opcodes/s390-opc.c
> index 9d9f0973e55..49efd714157 100644
> --- a/opcodes/s390-opc.c
> +++ b/opcodes/s390-opc.c
> @@ -36,7 +36,9 @@
>   
>   /* Build-time checks are preferrable over runtime ones.  Use this construct
>      in preference where possible.  */
> +#ifndef static_assert
>   #define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
> +#endif
>   
>   #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
>   

Thanks for taking care! LGTM.

Regards,
Jens
  

Patch

diff --git a/opcodes/i386-gen.c b/opcodes/i386-gen.c
index 053b66675c5..7ee8a30310c 100644
--- a/opcodes/i386-gen.c
+++ b/opcodes/i386-gen.c
@@ -30,7 +30,9 @@ 
 
 /* Build-time checks are preferrable over runtime ones.  Use this construct
    in preference where possible.  */
+#ifndef static_assert
 #define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
+#endif
 
 static const char *program_name = NULL;
 static int debug = 0;
diff --git a/opcodes/mips-formats.h b/opcodes/mips-formats.h
index 90df7100803..c4dec6352bf 100644
--- a/opcodes/mips-formats.h
+++ b/opcodes/mips-formats.h
@@ -49,7 +49,7 @@ 
 #define MAPPED_INT(SIZE, LSB, MAP, PRINT_HEX) \
   { \
     typedef char ATTRIBUTE_UNUSED \
-      static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
+      static_assert_3[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
     static const struct mips_mapped_int_operand op = { \
       { OP_MAPPED_INT, SIZE, LSB }, MAP, PRINT_HEX \
     }; \
@@ -83,7 +83,7 @@ 
 #define MAPPED_REG(SIZE, LSB, BANK, MAP) \
   { \
     typedef char ATTRIBUTE_UNUSED \
-      static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
+      static_assert_4[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
     static const struct mips_reg_operand op = { \
       { OP_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
     }; \
@@ -93,7 +93,7 @@ 
 #define OPTIONAL_MAPPED_REG(SIZE, LSB, BANK, MAP) \
   { \
     typedef char ATTRIBUTE_UNUSED \
-      static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
+      static_assert_5[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
     static const struct mips_reg_operand op = { \
       { OP_OPTIONAL_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
     }; \
diff --git a/opcodes/s390-opc.c b/opcodes/s390-opc.c
index 9d9f0973e55..49efd714157 100644
--- a/opcodes/s390-opc.c
+++ b/opcodes/s390-opc.c
@@ -36,7 +36,9 @@ 
 
 /* Build-time checks are preferrable over runtime ones.  Use this construct
    in preference where possible.  */
+#ifndef static_assert
 #define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
+#endif
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))