2
0

compiler.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. # endif
  40. #else
  41. #define GCC_ATTR /**/
  42. #define GCC_FMT_ATTR(n, m)
  43. #endif
  44. #endif /* COMPILER_H */