From 97ff87c0ed020c2a4b931146e142d67abe852e22 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Wed, 26 Sep 2018 17:48:50 +0200 Subject: qemu/compiler: Wrap __attribute__((flatten)) in a macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Older versions of Clang (before 3.5) and GCC (before 4.1) do not support the "__attribute__((flatten))" yet. We don't care about such old versions of GCC anymore, but since Clang 3.4 is still used in EPEL for RHEL7 / CentOS 7, we should not use this attribute directly but with a wrapper macro instead. Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson Signed-off-by: Thomas Huth --- include/qemu/compiler.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include/qemu') diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index bf47e7b..66f8c24 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -131,6 +131,21 @@ #define HAS_ASSUME_ALIGNED #endif +#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 the "flatten" attribute. Clang may not have the + * "flatten" attribute but always has __has_attribute() to check for it. + */ +#if __has_attribute(flatten) || !defined(__clang__) +# define QEMU_FLATTEN __attribute__((flatten)) +#else +# define QEMU_FLATTEN +#endif + /* Implement C11 _Generic via GCC builtins. Example: * * QEMU_GENERIC(x, (float, sinf), (long double, sinl), sin) (x) -- cgit v1.1