compiler.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 QEMU_BUILD_BUG_ON(x) \
  27. typedef char qemu_build_bug_on__##__LINE__[(x)?-1:1];
  28. #if defined __GNUC__
  29. # if !QEMU_GNUC_PREREQ(4, 4)
  30. /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
  31. # define GCC_ATTR __attribute__((__unused__, format(printf, 1, 2)))
  32. # define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m)))
  33. # else
  34. /* Use gnu_printf when supported (qemu uses standard format strings). */
  35. # define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2)))
  36. # define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
  37. # endif
  38. #else
  39. #define GCC_ATTR /**/
  40. #define GCC_FMT_ATTR(n, m)
  41. #endif
  42. #endif /* COMPILER_H */