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