s390x/kvm: fix cmma reset for KVM
[qemu/ar7.git] / include / qemu / compiler.h
blob157698bfa952956e585560031953e37093283b60
1 /* compiler.h: macros to abstract away compiler specifics
3 * This work is licensed under the terms of the GNU GPL, version 2 or later.
4 * See the COPYING file in the top-level directory.
5 */
7 #ifndef COMPILER_H
8 #define COMPILER_H
10 #if defined __clang_analyzer__ || defined __COVERITY__
11 #define QEMU_STATIC_ANALYSIS 1
12 #endif
14 /*----------------------------------------------------------------------------
15 | The macro QEMU_GNUC_PREREQ tests for minimum version of the GNU C compiler.
16 | The code is a copy of SOFTFLOAT_GNUC_PREREQ, see softfloat-macros.h.
17 *----------------------------------------------------------------------------*/
18 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
19 # define QEMU_GNUC_PREREQ(maj, min) \
20 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
21 #else
22 # define QEMU_GNUC_PREREQ(maj, min) 0
23 #endif
25 #define QEMU_NORETURN __attribute__ ((__noreturn__))
27 #if QEMU_GNUC_PREREQ(3, 4)
28 #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
29 #else
30 #define QEMU_WARN_UNUSED_RESULT
31 #endif
33 #if QEMU_GNUC_PREREQ(4, 0)
34 #define QEMU_SENTINEL __attribute__((sentinel))
35 #else
36 #define QEMU_SENTINEL
37 #endif
39 #if QEMU_GNUC_PREREQ(4, 3)
40 #define QEMU_ARTIFICIAL __attribute__((always_inline, artificial))
41 #else
42 #define QEMU_ARTIFICIAL
43 #endif
45 #if defined(_WIN32)
46 # define QEMU_PACKED __attribute__((gcc_struct, packed))
47 #else
48 # define QEMU_PACKED __attribute__((packed))
49 #endif
51 #define QEMU_ALIGNED(X) __attribute__((aligned(X)))
53 #ifndef glue
54 #define xglue(x, y) x ## y
55 #define glue(x, y) xglue(x, y)
56 #define stringify(s) tostring(s)
57 #define tostring(s) #s
58 #endif
60 #ifndef likely
61 #if __GNUC__ < 3
62 #define __builtin_expect(x, n) (x)
63 #endif
65 #define likely(x) __builtin_expect(!!(x), 1)
66 #define unlikely(x) __builtin_expect(!!(x), 0)
67 #endif
69 #ifndef container_of
70 #define container_of(ptr, type, member) ({ \
71 const typeof(((type *) 0)->member) *__mptr = (ptr); \
72 (type *) ((char *) __mptr - offsetof(type, member));})
73 #endif
75 /* Convert from a base type to a parent type, with compile time checking. */
76 #ifdef __GNUC__
77 #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
78 char __attribute__((unused)) offset_must_be_zero[ \
79 -offsetof(type, field)]; \
80 container_of(dev, type, field);}))
81 #else
82 #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
83 #endif
85 #define typeof_field(type, field) typeof(((type *)0)->field)
86 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
88 #define QEMU_BUILD_BUG_ON(x) \
89 typedef char glue(qemu_build_bug_on__,__LINE__)[(x)?-1:1] __attribute__((unused));
91 #if defined __GNUC__
92 # if !QEMU_GNUC_PREREQ(4, 4)
93 /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
94 # define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m)))
95 # else
96 /* Use gnu_printf when supported (qemu uses standard format strings). */
97 # define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
98 # if defined(_WIN32)
99 /* Map __printf__ to __gnu_printf__ because we want standard format strings
100 * even when MinGW or GLib include files use __printf__. */
101 # define __printf__ __gnu_printf__
102 # endif
103 # endif
104 #else
105 #define GCC_FMT_ATTR(n, m)
106 #endif
108 #endif /* COMPILER_H */