unicorn/qemu/include/qemu
Andreas Grapentin 4f6ba5a2dc
use _Static_assert in QEMU_BUILD_BUG_ON
QEMU_BUILD_BUG_ON should use C11's _Static_assert, if the compiler supports it,
to provide more readable messages on failure.

We check for _Static_assert in configure, and set CONFIG_STATIC_ASSERT
accordingly. QEMU_BUILD_BUG_ON invokes _Static_assert if CONFIG_STATIC_ASSERT
is defined, and reverts to the old way otherwise.

That way, systems without C11 conforming compiler will still have the old
messages, as verified by intentionally breaking the configure check.

the following example output was generated by inverting the condition in
QEMU_BUILD_BUG_ON:

without _Static_assert:

> In file included from /qemu/include/qemu/osdep.h:36:0,
> from /qemu/qga/commands.c:13:
> /qemu/qga/commands.c: In function ‘qmp_guest_exec_status’:
> /qemu/include/qemu/compiler.h:89:12: error: negative width in bit-field ‘<anonymous>’
> struct { \
> ^
> /qemu/include/qemu/compiler.h:96:38: note: in expansion of macro QEMU_BUILD_BUG_ON_STRUCT’
> #define QEMU_BUILD_BUG_ON(x) typedef QEMU_BUILD_BUG_ON_STRUCT(x) \
> ^~~~~~~~~~~~~~~~~~~~~~~~
> /qemu/include/qemu/atomic.h:146:5: note: in expansion of macro ‘QEMU_BUILD_BUG_ON’
> QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
> ^~~~~~~~~~~~~~~~~
> /qemu/include/qemu/atomic.h:417:5: note: in expansion of macro ‘atomic_load_acquire’
> atomic_load_acquire(ptr)
> ^~~~~~~~~~~~~~~~~~~
> /qemu/qga/commands.c:160:21: note: in expansion of macro ‘atomic_mb_read’
> bool finished = atomic_mb_read(&gei->finished);
> ^~~~~~~~~~~~~~

with _Static_assert:

> In file included from /qemu/include/qemu/osdep.h:36:0,
> from /qemu/qga/commands.c:13:
> /qemu/qga/commands.c: In function ‘qmp_guest_exec_status’:
> /qemu/include/qemu/compiler.h:94:30: error: static assertion failed: "not expecting: sizeof(*&gei->finished) > sizeof(void *)"
> #define QEMU_BUILD_BUG_ON(x) _Static_assert((x), #x)
> ^
> /qemu/include/qemu/atomic.h:146:5: note: in expansion of macro ‘QEMU_BUILD_BUG_ON’
> QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
> ^~~~~~~~~~~~~~~~~
> /qemu/include/qemu/atomic.h:417:5: note: in expansion of macro ‘atomic_load_acquire’
> atomic_load_acquire(ptr)
> ^~~~~~~~~~~~~~~~~~~
> /qemu/qga/commands.c:160:21: note: in expansion of macro ‘atomic_mb_read’
> bool finished = atomic_mb_read(&gei->finished);
> ^~~~~~~~~~~~~~

Backports commit 49e00a18708e27c815828d9440d5c9300d19547c from qemu
2018-03-20 10:42:20 -04:00
..
atomic.h qemu/atomic: Loosen restrictions for 64-bit ILP32 hosts 2018-03-02 20:06:39 -05:00
bitmap.h bitmap: provide to_le/from_le helpers 2018-03-05 01:11:13 -05:00
bitops.h bitops: Add MAKE_64BIT_MASK macro 2018-02-25 00:30:39 -05:00
bswap.h fpu/softfloat-types: new header to prevent excessive re-builds 2018-03-08 09:52:15 -05:00
compiler.h use _Static_assert in QEMU_BUILD_BUG_ON 2018-03-20 10:42:20 -04:00
cpuid.h util: Introduce include/qemu/cpuid.h 2018-03-09 12:12:00 -05:00
crc32c.h import 2015-08-21 15:04:50 +08:00
cutils.h cutils: add qemu_strtoi & qemu_strtoui parsers for int/unsigned int types 2018-03-17 19:13:34 -04:00
fprintf-fn.h Clean up decorations and whitespace around header guards 2018-02-25 04:26:02 -05:00
host-utils.h Drop QEMU_GNUC_PREREQ() checks for gcc older than 4.1 2018-03-02 18:59:05 -05:00
int128.h tcg: Add atomic128 helpers 2018-02-27 21:43:48 -05:00
log.h tcg: Lower indirect registers in a separate pass 2018-02-25 22:32:28 -05:00
mmap-alloc.h Clean up ill-advised or unusual header guards 2018-02-25 04:22:46 -05:00
module.h cleanup qemu/include/qemu/module.h 2017-01-25 00:20:08 +08:00
osdep.h osdep.h: Make TIME_MAX handle different time_t types 2018-03-05 13:48:29 -05:00
queue.h tcg: Dynamically allocate TCGOps 2018-03-05 16:34:40 -05:00
range.h range: Replace internal representation of Range 2018-02-25 00:44:36 -05:00
sys_membarrier.h membarrier: add --enable-membarrier 2018-03-17 19:30:43 -04:00
thread-posix.h Clean up ill-advised or unusual header guards 2018-02-25 04:22:46 -05:00
thread-win32.h Clean up ill-advised or unusual header guards 2018-02-25 04:22:46 -05:00
thread.h Clean up ill-advised or unusual header guards 2018-02-25 04:22:46 -05:00
timer.h Drop remaining bits of ia64 host support 2018-03-09 11:54:57 -05:00
typedefs.h memory: Move AddressSpaceDispatch from AddressSpace to FlatView 2018-03-11 20:40:24 -04:00