[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] qemu/compiler: Wrap __attribute__((flatten)) in
From: |
Peter Maydell |
Subject: |
Re: [Qemu-devel] [PATCH] qemu/compiler: Wrap __attribute__((flatten)) in a macro |
Date: |
Wed, 26 Sep 2018 19:57:29 +0100 |
On 26 September 2018 at 16:59, Thomas Huth <address@hidden> wrote:
> +/*
> + * Clang 3.4 claims to be compatible with GCC 4.2, but does not have the
> + * "flatten" attribute, so we've got to handle Clang via __has_attribute here
> + */
> +#if defined(__clang__) && defined(__has_attribute)
> +# if __has_attribute(flatten)
> +# define QEMU_FLATTEN __attribute__((flatten))
> +# endif
> +#elif !defined(__clang__) && QEMU_GNUC_PREREQ(4, 1)
> +# define QEMU_FLATTEN __attribute__((flatten))
> +#endif
> +#ifndef QEMU_FLATTEN
> +# define QEMU_FLATTEN
> +#endif
I think it would be cleaner to say: if we have __has_attribute,
trust it; otherwise fall back to version testing. Also, we
already require at least GCC 4.1 so a version test against
that is unnecessary. So something like:
#ifndef __has_attribute
#define __has_attribute(x) 0 / compatibility with older GCC */
#endif
/*
* gcc doesn't provide __has_attribute() until gcc 5,
* but we know all the gcc versions we support have flatten.
* clang may not have flatten but always has __has_attribute().
*/
#if __has_attribute(flatten) || !defined(__clang__)
# define QEMU_FLATTEN __attribute__((flatten))
#else
# define QEMU_FLATTEN
#endif
> +
> #ifndef __has_feature
> #define __has_feature(x) 0 /* compatibility with non-clang compilers */
> #endif
> --
> 1.8.3.1
thanks
-- PMM