blob: c734a71c67ac1a65d3ec45ccaceb6624226a5b68 [file] [log] [blame]
Luiz Capitulino5c026322011-07-11 14:24:44 -03001/* public domain */
2
3#ifndef COMPILER_H
4#define COMPILER_H
5
6#include "config-host.h"
7
Stefan Weilf8b72752011-09-16 22:03:07 +02008/*----------------------------------------------------------------------------
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 Capitulino5c026322011-07-11 14:24:44 -030019#define QEMU_NORETURN __attribute__ ((__noreturn__))
Stefan Weilf8b72752011-09-16 22:03:07 +020020
Stefan Weil87751792011-09-16 22:03:08 +020021#if QEMU_GNUC_PREREQ(3, 4)
Luiz Capitulino5c026322011-07-11 14:24:44 -030022#define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
23#else
24#define QEMU_WARN_UNUSED_RESULT
25#endif
26
Stefan Weil0f7fdd32011-08-31 12:38:00 +020027#if defined(_WIN32)
28# define QEMU_PACKED __attribute__((gcc_struct, packed))
29#else
30# define QEMU_PACKED __attribute__((packed))
31#endif
32
Dong Xu Wangea8f9782011-12-20 17:03:47 +080033#define cat(x,y) x ## y
34#define cat2(x,y) cat(x,y)
Luiz Capitulino5c026322011-07-11 14:24:44 -030035#define QEMU_BUILD_BUG_ON(x) \
Dong Xu Wangea8f9782011-12-20 17:03:47 +080036 typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1];
Luiz Capitulino5c026322011-07-11 14:24:44 -030037
38#if defined __GNUC__
Stefan Weilf8b72752011-09-16 22:03:07 +020039# if !QEMU_GNUC_PREREQ(4, 4)
Luiz Capitulino5c026322011-07-11 14:24:44 -030040 /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
41# define GCC_ATTR __attribute__((__unused__, format(printf, 1, 2)))
42# define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m)))
43# else
44 /* Use gnu_printf when supported (qemu uses standard format strings). */
45# define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2)))
46# define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
Stefan Weil95df51a2012-08-22 21:42:32 +020047# if defined(_WIN32)
48 /* Map __printf__ to __gnu_printf__ because we want standard format strings
49 * even when MinGW or GLib include files use __printf__. */
50# define __printf__ __gnu_printf__
51# endif
Luiz Capitulino5c026322011-07-11 14:24:44 -030052# endif
Anthony Liguori76b64a72012-08-14 22:17:36 -050053#if defined(_WIN32)
Anthony Liguori6ee373a2012-08-10 11:04:12 -050054#define GCC_WEAK __attribute__((weak))
Anthony Liguori76b64a72012-08-14 22:17:36 -050055#define GCC_WEAK_DECL GCC_WEAK
56#else
57#define GCC_WEAK __attribute__((weak))
58#define GCC_WEAK_DECL
59#endif
Luiz Capitulino5c026322011-07-11 14:24:44 -030060#else
61#define GCC_ATTR /**/
62#define GCC_FMT_ATTR(n, m)
63#endif
64
65#endif /* COMPILER_H */