[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] QEMU_BUILD_BUG_ON: use __COUNTER__
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH] QEMU_BUILD_BUG_ON: use __COUNTER__ |
Date: |
Tue, 31 Jan 2017 09:03:10 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 |
On 01/31/2017 08:43 AM, Michael S. Tsirkin wrote:
> Some headers use QEMU_BUILD_BUG_ON. This causes a problem
> if the C file including that header happens to have
> QEMU_BUILD_BUG_ON at the same line number.
>
> Fix using a widely available extension: __COUNTER__.
gcc 4.3 and later; clang documents it but doesn't say when it was added.
> If unavailable, provide a stub.
What fails in our build farm if we don't provide the stub? Can we just
require that our compiler is new enough to have __COUNTER__, or will
that break some of our existing targets?
>
> Signed-off-by: Michael S. Tsirkin <address@hidden>
> ---
> include/qemu/compiler.h | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
> index e0fb18b..bad25a9 100644
> --- a/include/qemu/compiler.h
> +++ b/include/qemu/compiler.h
> @@ -89,8 +89,12 @@
> struct { \
> int:(x) ? -1 : 1; \
> }
> +#ifdef __COUNTER__
Better would be:
#if defined __COUNTER__ && __COUNTER__ != __COUNTER__
to ensure that it has the semantics we need (that's what gnulib's
LGPLv2+ verify.h uses).
> #define QEMU_BUILD_BUG_ON(x) typedef QEMU_BUILD_BUG_ON_STRUCT(x) \
> - glue(qemu_build_bug_on__, __LINE__) __attribute__((unused))
> + glue(qemu_build_bug_on__, __COUNTER__) __attribute__((unused))
But I agree that this is the right change to make.
> +#else
> +#define QEMU_BUILD_BUG_ON(x)
This means we lose sanity checks on older compilers. Gnulib documents
that on older compilers, you can use:
extern int (*dummy (void)) [sizeof (struct {...})];
coupled with -Wno-redundant-decls, which lets you redeclare the same
thing as many times as you want without any use of __LINE__ or
__COUNTER__. On the other hand, I don't think we have to bend over
backwards for compilers that old (RHEL 6 is at gcc 4.4.7, but 4.3 has
__COUNTER__).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
Re: [Qemu-devel] [PATCH] QEMU_BUILD_BUG_ON: use __COUNTER__, Markus Armbruster, 2017/01/31