0004-opcodes-fix-std-gnu23-compatibility-wrt-static_asser.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. From 8ebe62f3f0d27806b1bf69f301f5e188b4acd2b4 Mon Sep 17 00:00:00 2001
  2. From: Sam James <sam@gentoo.org>
  3. Date: Sat, 16 Nov 2024 05:03:52 +0000
  4. Subject: [PATCH] opcodes: fix -std=gnu23 compatibility wrt static_assert
  5. static_assert is declared in C23 so we can't reuse that identifier:
  6. * Define our own static_assert conditionally;
  7. * Rename "static assert" hacks to _N as we do already in some places
  8. to avoid a conflict.
  9. ChangeLog:
  10. PR ld/32372
  11. * i386-gen.c (static_assert): Define conditionally.
  12. * mips-formats.h (MAPPED_INT): Rename identifier.
  13. (MAPPED_REG): Rename identifier.
  14. (OPTIONAL_MAPPED_REG): Rename identifier.
  15. * s390-opc.c (static_assert): Define conditionally.
  16. Upstream: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=8ebe62f3f0d27806b1bf69f301f5e188b4acd2b4
  17. Signed-off-by: Raphaël Mélotte <raphael.melotte@mind.be>
  18. ---
  19. opcodes/i386-gen.c | 2 ++
  20. opcodes/mips-formats.h | 6 +++---
  21. opcodes/s390-opc.c | 2 ++
  22. 3 files changed, 7 insertions(+), 3 deletions(-)
  23. diff --git a/opcodes/i386-gen.c b/opcodes/i386-gen.c
  24. index 053b66675c5..7ee8a30310c 100644
  25. --- a/opcodes/i386-gen.c
  26. +++ b/opcodes/i386-gen.c
  27. @@ -30,7 +30,9 @@
  28. /* Build-time checks are preferrable over runtime ones. Use this construct
  29. in preference where possible. */
  30. +#ifndef static_assert
  31. #define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
  32. +#endif
  33. static const char *program_name = NULL;
  34. static int debug = 0;
  35. diff --git a/opcodes/mips-formats.h b/opcodes/mips-formats.h
  36. index 90df7100803..c4dec6352bf 100644
  37. --- a/opcodes/mips-formats.h
  38. +++ b/opcodes/mips-formats.h
  39. @@ -49,7 +49,7 @@
  40. #define MAPPED_INT(SIZE, LSB, MAP, PRINT_HEX) \
  41. { \
  42. typedef char ATTRIBUTE_UNUSED \
  43. - static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
  44. + static_assert_3[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
  45. static const struct mips_mapped_int_operand op = { \
  46. { OP_MAPPED_INT, SIZE, LSB }, MAP, PRINT_HEX \
  47. }; \
  48. @@ -83,7 +83,7 @@
  49. #define MAPPED_REG(SIZE, LSB, BANK, MAP) \
  50. { \
  51. typedef char ATTRIBUTE_UNUSED \
  52. - static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
  53. + static_assert_4[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
  54. static const struct mips_reg_operand op = { \
  55. { OP_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
  56. }; \
  57. @@ -93,7 +93,7 @@
  58. #define OPTIONAL_MAPPED_REG(SIZE, LSB, BANK, MAP) \
  59. { \
  60. typedef char ATTRIBUTE_UNUSED \
  61. - static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
  62. + static_assert_5[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
  63. static const struct mips_reg_operand op = { \
  64. { OP_OPTIONAL_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
  65. }; \
  66. diff --git a/opcodes/s390-opc.c b/opcodes/s390-opc.c
  67. index 9d9f0973e55..49efd714157 100644
  68. --- a/opcodes/s390-opc.c
  69. +++ b/opcodes/s390-opc.c
  70. @@ -36,7 +36,9 @@
  71. /* Build-time checks are preferrable over runtime ones. Use this construct
  72. in preference where possible. */
  73. +#ifndef static_assert
  74. #define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
  75. +#endif
  76. #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
  77. --
  78. 2.34.1