Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gcc_compat.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
  3. * Copyright (c) 2015-2018 The strace developers.
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: LGPL-2.1-or-later
  7. */
  8. #ifndef STRACE_GCC_COMPAT_H
  9. # define STRACE_GCC_COMPAT_H
  10. # if defined __GNUC__ && defined __GNUC_MINOR__
  11. # define GNUC_PREREQ(maj, min) \
  12. ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
  13. # else
  14. # define GNUC_PREREQ(maj, min) 0
  15. # endif
  16. # if defined __clang__ && defined __clang_major__ && defined __clang_minor__
  17. # define CLANG_PREREQ(maj, min) \
  18. ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
  19. # else
  20. # define CLANG_PREREQ(maj, min) 0
  21. # endif
  22. # if !(GNUC_PREREQ(2, 0) || CLANG_PREREQ(1, 0))
  23. # define __attribute__(x) /* empty */
  24. # endif
  25. # if GNUC_PREREQ(2, 5)
  26. # define ATTRIBUTE_NORETURN __attribute__((__noreturn__))
  27. # else
  28. # define ATTRIBUTE_NORETURN /* empty */
  29. # endif
  30. # if GNUC_PREREQ(2, 7)
  31. # define ATTRIBUTE_FORMAT(args) __attribute__((__format__ args))
  32. # define ATTRIBUTE_ALIGNED(arg) __attribute__((__aligned__(arg)))
  33. # define ATTRIBUTE_PACKED __attribute__((__packed__))
  34. # else
  35. # define ATTRIBUTE_FORMAT(args) /* empty */
  36. # define ATTRIBUTE_ALIGNED(arg) /* empty */
  37. # define ATTRIBUTE_PACKED /* empty */
  38. # endif
  39. # if GNUC_PREREQ(3, 0)
  40. # define SAME_TYPE(x, y) __builtin_types_compatible_p(typeof(x), typeof(y))
  41. # define FAIL_BUILD_ON_ZERO(expr) (sizeof(int[-1 + 2 * !!(expr)]) * 0)
  42. /* &(a)[0] is a pointer and not an array, shouldn't be treated as the same */
  43. # define MUST_BE_ARRAY(a) FAIL_BUILD_ON_ZERO(!SAME_TYPE((a), &(a)[0]))
  44. # else
  45. # define SAME_TYPE(x, y) 0
  46. # define MUST_BE_ARRAY(a) 0
  47. # endif
  48. # if GNUC_PREREQ(3, 0)
  49. # define ATTRIBUTE_MALLOC __attribute__((__malloc__))
  50. # else
  51. # define ATTRIBUTE_MALLOC /* empty */
  52. # endif
  53. # if GNUC_PREREQ(3, 1)
  54. # define ATTRIBUTE_NOINLINE __attribute__((__noinline__))
  55. # else
  56. # define ATTRIBUTE_NOINLINE /* empty */
  57. # endif
  58. # if GNUC_PREREQ(4, 0)
  59. # define ATTRIBUTE_SENTINEL __attribute__((__sentinel__))
  60. # else
  61. # define ATTRIBUTE_SENTINEL /* empty */
  62. # endif
  63. # if GNUC_PREREQ(4, 1)
  64. # define ALIGNOF(t_) __alignof__(t_)
  65. # else
  66. # define ALIGNOF(t_) (sizeof(struct { char x_; t_ y_; }) - sizeof(t_))
  67. # endif
  68. # if GNUC_PREREQ(4, 3)
  69. # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__((__alloc_size__ args))
  70. # else
  71. # define ATTRIBUTE_ALLOC_SIZE(args) /* empty */
  72. # endif
  73. # if GNUC_PREREQ(7, 0)
  74. # define ATTRIBUTE_FALLTHROUGH __attribute__((__fallthrough__))
  75. # else
  76. # define ATTRIBUTE_FALLTHROUGH ((void) 0)
  77. # endif
  78. # if CLANG_PREREQ(2, 8)
  79. # define DIAG_PUSH_IGNORE_OVERRIDE_INIT \
  80. _Pragma("clang diagnostic push"); \
  81. _Pragma("clang diagnostic ignored \"-Winitializer-overrides\"");
  82. # define DIAG_POP_IGNORE_OVERRIDE_INIT \
  83. _Pragma("clang diagnostic pop");
  84. # elif GNUC_PREREQ(4, 2)
  85. # define DIAG_PUSH_IGNORE_OVERRIDE_INIT \
  86. _Pragma("GCC diagnostic push"); \
  87. _Pragma("GCC diagnostic ignored \"-Woverride-init\"");
  88. # define DIAG_POP_IGNORE_OVERRIDE_INIT \
  89. _Pragma("GCC diagnostic pop");
  90. # else
  91. # define DIAG_PUSH_IGNORE_OVERRIDE_INIT /* empty */
  92. # define DIAG_POP_IGNORE_OVERRIDE_INIT /* empty */
  93. # endif
  94. # if GNUC_PREREQ(6, 0)
  95. # define DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE \
  96. _Pragma("GCC diagnostic push"); \
  97. _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"");
  98. # define DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE \
  99. _Pragma("GCC diagnostic pop");
  100. # else
  101. # define DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE /* empty */
  102. # define DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE /* empty */
  103. # endif
  104. #endif /* !STRACE_GCC_COMPAT_H */