1
0

compiler.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* public domain */
  2. #ifndef COMPILER_H
  3. #define COMPILER_H
  4. #include "config-host.h"
  5. /*----------------------------------------------------------------------------
  6. | The macro QEMU_GNUC_PREREQ tests for minimum version of the GNU C compiler.
  7. | The code is a copy of SOFTFLOAT_GNUC_PREREQ, see softfloat-macros.h.
  8. *----------------------------------------------------------------------------*/
  9. #if defined(__GNUC__) && defined(__GNUC_MINOR__)
  10. # define QEMU_GNUC_PREREQ(maj, min) \
  11. ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
  12. #else
  13. # define QEMU_GNUC_PREREQ(maj, min) 0
  14. #endif
  15. #define QEMU_NORETURN __attribute__ ((__noreturn__))
  16. #if QEMU_GNUC_PREREQ(3, 4)
  17. #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  18. #else
  19. #define QEMU_WARN_UNUSED_RESULT
  20. #endif
  21. #if defined(_WIN32)
  22. # define QEMU_PACKED __attribute__((gcc_struct, packed))
  23. #else
  24. # define QEMU_PACKED __attribute__((packed))
  25. #endif
  26. #define cat(x,y) x ## y
  27. #define cat2(x,y) cat(x,y)
  28. #define QEMU_BUILD_BUG_ON(x) \
  29. typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1];
  30. #if defined __GNUC__
  31. # if !QEMU_GNUC_PREREQ(4, 4)
  32. /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
  33. # define GCC_ATTR __attribute__((__unused__, format(printf, 1, 2)))
  34. # define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m)))
  35. # else
  36. /* Use gnu_printf when supported (qemu uses standard format strings). */
  37. # define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2)))
  38. # define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
  39. # if defined(_WIN32)
  40. /* Map __printf__ to __gnu_printf__ because we want standard format strings
  41. * even when MinGW or GLib include files use __printf__. */
  42. # define __printf__ __gnu_printf__
  43. # endif
  44. # endif
  45. #else
  46. #define GCC_ATTR /**/
  47. #define GCC_FMT_ATTR(n, m)
  48. #endif
  49. #endif /* COMPILER_H */