003-PR-32372-opcodes-fix-std-gnu23-compatibility-wrt-static_asser.patch 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. From 8ebe62f3f0d27806b1bf69f301f5e188b4acd2b4 Mon Sep 17 00:00:00 2001
  2. From: Sam James <[email protected]>
  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. ---
  17. opcodes/i386-gen.c | 2 ++
  18. opcodes/mips-formats.h | 6 +++---
  19. opcodes/s390-opc.c | 2 ++
  20. 3 files changed, 7 insertions(+), 3 deletions(-)
  21. --- a/opcodes/i386-gen.c
  22. +++ b/opcodes/i386-gen.c
  23. @@ -30,7 +30,9 @@
  24. /* Build-time checks are preferrable over runtime ones. Use this construct
  25. in preference where possible. */
  26. +#ifndef static_assert
  27. #define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
  28. +#endif
  29. static const char *program_name = NULL;
  30. static int debug = 0;
  31. --- a/opcodes/mips-formats.h
  32. +++ b/opcodes/mips-formats.h
  33. @@ -49,7 +49,7 @@
  34. #define MAPPED_INT(SIZE, LSB, MAP, PRINT_HEX) \
  35. { \
  36. typedef char ATTRIBUTE_UNUSED \
  37. - static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
  38. + static_assert_3[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
  39. static const struct mips_mapped_int_operand op = { \
  40. { OP_MAPPED_INT, SIZE, LSB }, MAP, PRINT_HEX \
  41. }; \
  42. @@ -83,7 +83,7 @@
  43. #define MAPPED_REG(SIZE, LSB, BANK, MAP) \
  44. { \
  45. typedef char ATTRIBUTE_UNUSED \
  46. - static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
  47. + static_assert_4[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
  48. static const struct mips_reg_operand op = { \
  49. { OP_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
  50. }; \
  51. @@ -93,7 +93,7 @@
  52. #define OPTIONAL_MAPPED_REG(SIZE, LSB, BANK, MAP) \
  53. { \
  54. typedef char ATTRIBUTE_UNUSED \
  55. - static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
  56. + static_assert_5[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
  57. static const struct mips_reg_operand op = { \
  58. { OP_OPTIONAL_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
  59. }; \
  60. --- a/opcodes/s390-opc.c
  61. +++ b/opcodes/s390-opc.c
  62. @@ -36,7 +36,9 @@
  63. /* Build-time checks are preferrable over runtime ones. Use this construct
  64. in preference where possible. */
  65. +#ifndef static_assert
  66. #define static_assert(e) ((void)sizeof (struct { int _:1 - 2 * !(e); }))
  67. +#endif
  68. #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))