Correct Clang feature detection

Clang's __GNUC__ and __GNUC_MINOR__ definitions are not reliable and may
not be defined at all when targeting the MSVC ABI. Use feature-checking
macros when possible or check for __clang__.

[guillem@hadrons.org: Update for __ protected keyword change. ]

Signed-off-by: Guillem Jover <guillem@hadrons.org>
This commit is contained in:
Aaron Dierking 2018-06-14 11:38:31 -07:00 committed by Guillem Jover
parent 574c7a1365
commit 7cfa2d4530
2 changed files with 20 additions and 13 deletions

View File

@ -30,6 +30,13 @@
#ifndef __has_include_next #ifndef __has_include_next
#define __has_include_next(x) 1 #define __has_include_next(x) 1
#endif #endif
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
/* Clang expands this to 1 if an identifier is *not* reserved. */
#ifndef __is_identifier
#define __is_identifier(x) 1
#endif
#ifdef LIBBSD_OVERLAY #ifdef LIBBSD_OVERLAY
/* /*
@ -85,7 +92,7 @@
#define LIBBSD_GCC_VERSION 0 #define LIBBSD_GCC_VERSION 0
#endif #endif
#if LIBBSD_GCC_VERSION >= 0x0405 #if LIBBSD_GCC_VERSION >= 0x0405 || __has_attribute(__deprecated__)
#define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__(x))) #define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__(x)))
#elif LIBBSD_GCC_VERSION >= 0x0301 #elif LIBBSD_GCC_VERSION >= 0x0301
#define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__)) #define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__))
@ -93,14 +100,14 @@
#define LIBBSD_DEPRECATED(x) #define LIBBSD_DEPRECATED(x)
#endif #endif
#if LIBBSD_GCC_VERSION >= 0x0200 #if LIBBSD_GCC_VERSION >= 0x0200 || defined(__clang__)
#define LIBBSD_REDIRECT(name, proto, alias) name proto __asm__(LIBBSD_ASMNAME(#alias)) #define LIBBSD_REDIRECT(name, proto, alias) name proto __asm__(LIBBSD_ASMNAME(#alias))
#endif #endif
#define LIBBSD_ASMNAME(cname) LIBBSD_ASMNAME_PREFIX(__USER_LABEL_PREFIX__, cname) #define LIBBSD_ASMNAME(cname) LIBBSD_ASMNAME_PREFIX(__USER_LABEL_PREFIX__, cname)
#define LIBBSD_ASMNAME_PREFIX(prefix, cname) LIBBSD_STRING(prefix) cname #define LIBBSD_ASMNAME_PREFIX(prefix, cname) LIBBSD_STRING(prefix) cname
#ifndef __dead2 #ifndef __dead2
# if LIBBSD_GCC_VERSION >= 0x0207 # if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__noreturn__)
# define __dead2 __attribute__((__noreturn__)) # define __dead2 __attribute__((__noreturn__))
# else # else
# define __dead2 # define __dead2
@ -108,7 +115,7 @@
#endif #endif
#ifndef __pure2 #ifndef __pure2
# if LIBBSD_GCC_VERSION >= 0x0207 # if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__const__)
# define __pure2 __attribute__((__const__)) # define __pure2 __attribute__((__const__))
# else # else
# define __pure2 # define __pure2
@ -116,7 +123,7 @@
#endif #endif
#ifndef __packed #ifndef __packed
# if LIBBSD_GCC_VERSION >= 0x0207 # if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__packed__)
# define __packed __attribute__((__packed__)) # define __packed __attribute__((__packed__))
# else # else
# define __packed # define __packed
@ -124,7 +131,7 @@
#endif #endif
#ifndef __aligned #ifndef __aligned
# if LIBBSD_GCC_VERSION >= 0x0207 # if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__aligned__)
# define __aligned(x) __attribute__((__aligned__(x))) # define __aligned(x) __attribute__((__aligned__(x)))
# else # else
# define __aligned(x) # define __aligned(x)
@ -145,7 +152,7 @@
#endif #endif
#ifndef __printflike #ifndef __printflike
# if LIBBSD_GCC_VERSION >= 0x0300 # if LIBBSD_GCC_VERSION >= 0x0300 || __has_attribute(__format__)
# define __printflike(x, y) __attribute((__format__(__printf__, (x), (y)))) # define __printflike(x, y) __attribute((__format__(__printf__, (x), (y))))
# else # else
# define __printflike(x, y) # define __printflike(x, y)
@ -153,7 +160,7 @@
#endif #endif
#ifndef __nonnull #ifndef __nonnull
# if LIBBSD_GCC_VERSION >= 0x0302 # if LIBBSD_GCC_VERSION >= 0x0302 || __has_attribute(__nonnull__)
# define __nonnull(x) __attribute__((__nonnull__(x))) # define __nonnull(x) __attribute__((__nonnull__(x)))
# else # else
# define __nonnull(x) # define __nonnull(x)
@ -175,7 +182,7 @@
* require it. * require it.
*/ */
#ifndef __offsetof #ifndef __offsetof
# if LIBBSD_GCC_VERSION >= 0x0401 # if LIBBSD_GCC_VERSION >= 0x0401 || !__is_identifier(__builtin_offsetof)
# define __offsetof(type, field) __builtin_offsetof(type, field) # define __offsetof(type, field) __builtin_offsetof(type, field)
# else # else
# ifndef __cplusplus # ifndef __cplusplus
@ -200,7 +207,7 @@
* compatible with member m. * compatible with member m.
*/ */
#ifndef __containerof #ifndef __containerof
# if LIBBSD_GCC_VERSION >= 0x0301 # if LIBBSD_GCC_VERSION >= 0x0301 || !__is_identifier(__typeof__)
# define __containerof(x, s, m) ({ \ # define __containerof(x, s, m) ({ \
const volatile __typeof__(((s *)0)->m) *__x = (x); \ const volatile __typeof__(((s *)0)->m) *__x = (x); \
__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m)); \ __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m)); \

View File

@ -39,11 +39,11 @@
#define minimum(a, b) ((a) < (b) ? (a) : (b)) #define minimum(a, b) ((a) < (b) ? (a) : (b))
#if defined(__GNUC__) || defined(_MSC_VER) #if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)
#define inline __inline #define inline __inline
#else /* __GNUC__ || _MSC_VER */ #else /* __GNUC__ || __clang__ || _MSC_VER */
#define inline #define inline
#endif /* !__GNUC__ && !_MSC_VER */ #endif /* !__GNUC__ && !__clang__ && !_MSC_VER */
#define KEYSZ 32 #define KEYSZ 32
#define IVSZ 8 #define IVSZ 8