From: Andreas Grapentin <andreas@grapentin.org>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Andreas Grapentin <andreas@grapentin.org>
Subject: [Qemu-devel] [PATCH 0/1] Developer Conveniences - check for _Static_assert and use in QEMU_BUILD_BUG_ON
Date: Tue, 14 Mar 2017 15:44:52 +0100 [thread overview]
Message-ID: <20170314144453.5027-1-andreas@grapentin.org> (raw)
(as taken from here: http://wiki.qemu-project.org/Contribute/BiteSizedTasks)
I added a configure check for C11's _Static_assert, and based on the outcome,
QEMU_BUILD_BUG_ON will now produce slightly more readable results on failures.
Systems without C11 conforming compilers 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 /home/andi/research/qemu-shared-memory/qemu/include/qemu/osdep.h:36:0,
> from /home/andi/research/qemu-shared-memory/qemu/qga/commands.c:13:
> /home/andi/research/qemu-shared-memory/qemu/qga/commands.c: In function ‘qmp_guest_exec_status’:
> /home/andi/research/qemu-shared-memory/qemu/include/qemu/compiler.h:89:12: error: negative width in bit-field ‘<anonymous>’
> struct { \
> ^
> /home/andi/research/qemu-shared-memory/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) \
> ^~~~~~~~~~~~~~~~~~~~~~~~
> /home/andi/research/qemu-shared-memory/qemu/include/qemu/atomic.h:146:5: note: in expansion of macro ‘QEMU_BUILD_BUG_ON’
> QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
> ^~~~~~~~~~~~~~~~~
> /home/andi/research/qemu-shared-memory/qemu/include/qemu/atomic.h:417:5: note: in expansion of macro ‘atomic_load_acquire’
> atomic_load_acquire(ptr)
> ^~~~~~~~~~~~~~~~~~~
> /home/andi/research/qemu-shared-memory/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 /home/andi/research/qemu-shared-memory/qemu/include/qemu/osdep.h:36:0,
> from /home/andi/research/qemu-shared-memory/qemu/qga/commands.c:13:
> /home/andi/research/qemu-shared-memory/qemu/qga/commands.c: In function ‘qmp_guest_exec_status’:
> /home/andi/research/qemu-shared-memory/qemu/include/qemu/compiler.h:94:30: error: static assertion failed: "sizeof(*&gei->finished) > sizeof(void *)"
> #define QEMU_BUILD_BUG_ON(x) _Static_assert((x), #x)
> ^
> /home/andi/research/qemu-shared-memory/qemu/include/qemu/atomic.h:146:5: note: in expansion of macro ‘QEMU_BUILD_BUG_ON’
> QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
> ^~~~~~~~~~~~~~~~~
> /home/andi/research/qemu-shared-memory/qemu/include/qemu/atomic.h:417:5: note: in expansion of macro ‘atomic_load_acquire’
> atomic_load_acquire(ptr)
> ^~~~~~~~~~~~~~~~~~~
> /home/andi/research/qemu-shared-memory/qemu/qga/commands.c:160:21: note: in expansion of macro ‘atomic_mb_read’
> bool finished = atomic_mb_read(&gei->finished);
> ^~~~~~~~~~~~~~
Andreas Grapentin (1):
added configure check for _Static_assert and updated
QEMU_BUILD_BUG_ON(...) accordingly
configure | 18 ++++++++++++++++++
include/qemu/compiler.h | 4 +++-
2 files changed, 21 insertions(+), 1 deletion(-)
--
2.12.0
next reply other threads:[~2017-03-14 14:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-14 14:44 Andreas Grapentin [this message]
2017-03-14 14:44 ` [Qemu-devel] [PATCH 1/1] added configure check for _Static_assert and updated QEMU_BUILD_BUG_ON(...) accordingly Andreas Grapentin
2017-03-14 15:08 ` Eric Blake
2017-03-14 14:58 ` [Qemu-devel] [PATCH 0/1] Developer Conveniences - check for _Static_assert and use in QEMU_BUILD_BUG_ON Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170314144453.5027-1-andreas@grapentin.org \
--to=andreas@grapentin.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).