6 #include "config-host.h"
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))
16 # define QEMU_GNUC_PREREQ(maj, min) 0
19 #define QEMU_NORETURN __attribute__ ((__noreturn__))
21 #if QEMU_GNUC_PREREQ(3, 4)
22 #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
24 #define QEMU_WARN_UNUSED_RESULT
27 #if QEMU_GNUC_PREREQ(4, 0)
28 #define QEMU_SENTINEL __attribute__((sentinel))
33 #if QEMU_GNUC_PREREQ(4, 3)
34 #define QEMU_ARTIFICIAL __attribute__((always_inline, artificial))
36 #define QEMU_ARTIFICIAL
40 # define QEMU_PACKED __attribute__((gcc_struct, packed))
42 # define QEMU_PACKED __attribute__((packed))
46 #define xglue(x, y) x ## y
47 #define glue(x, y) xglue(x, y)
48 #define stringify(s) tostring(s)
49 #define tostring(s) #s
54 #define __builtin_expect(x, n) (x)
57 #define likely(x) __builtin_expect(!!(x), 1)
58 #define unlikely(x) __builtin_expect(!!(x), 0)
62 #define container_of(ptr, type, member) ({ \
63 const typeof(((type *) 0)->member) *__mptr = (ptr); \
64 (type *) ((char *) __mptr - offsetof(type, member));})
67 /* Convert from a base type to a parent type, with compile time checking. */
69 #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
70 char __attribute__((unused)) offset_must_be_zero[ \
71 -offsetof(type, field)]; \
72 container_of(dev, type, field);}))
74 #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
77 #define typeof_field(type, field) typeof(((type *)0)->field)
78 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
81 #if !((__GNUC__ < 3) || defined(__APPLE__))
84 #define inline __attribute__ (( always_inline )) __inline__
89 #define inline always_inline
92 #define QEMU_BUILD_BUG_ON(x) \
93 typedef char glue(qemu_build_bug_on__,__LINE__)[(x)?-1:1] __attribute__((unused));
96 # if !QEMU_GNUC_PREREQ(4, 4)
97 /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
98 # define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m)))
100 /* Use gnu_printf when supported (qemu uses standard format strings). */
101 # define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
103 /* Map __printf__ to __gnu_printf__ because we want standard format strings
104 * even when MinGW or GLib include files use __printf__. */
105 # define __printf__ __gnu_printf__
109 #define GCC_FMT_ATTR(n, m)
112 #endif /* COMPILER_H */