]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
Correct Clang feature detection
authorAaron Dierking <aarond@fb.com>
Thu, 14 Jun 2018 18:38:31 +0000 (11:38 -0700)
committerGuillem Jover <guillem@hadrons.org>
Mon, 18 Jun 2018 02:31:00 +0000 (04:31 +0200)
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>
include/bsd/sys/cdefs.h
src/arc4random.c

index c574fc2728260b6f6e01e21f5d508bfb414a4c5c..999bda22c7998eef902d5d9ced8b2fe0a45b2ce7 100644 (file)
 #ifndef __has_include_next
 #define __has_include_next(x) 1
 #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
 /*
@@ -85,7 +92,7 @@
 #define LIBBSD_GCC_VERSION 0
 #endif
 
-#if LIBBSD_GCC_VERSION >= 0x0405
+#if LIBBSD_GCC_VERSION >= 0x0405 || __has_attribute(__deprecated__)
 #define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__(x)))
 #elif LIBBSD_GCC_VERSION >= 0x0301
 #define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__))
 #define LIBBSD_DEPRECATED(x)
 #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))
 #endif
 #define LIBBSD_ASMNAME(cname) LIBBSD_ASMNAME_PREFIX(__USER_LABEL_PREFIX__, cname)
 #define LIBBSD_ASMNAME_PREFIX(prefix, cname) LIBBSD_STRING(prefix) cname
 
 #ifndef __dead2
-# if LIBBSD_GCC_VERSION >= 0x0207
+# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__noreturn__)
 #  define __dead2 __attribute__((__noreturn__))
 # else
 #  define __dead2
 #endif
 
 #ifndef __pure2
-# if LIBBSD_GCC_VERSION >= 0x0207
+# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__const__)
 #  define __pure2 __attribute__((__const__))
 # else
 #  define __pure2
 #endif
 
 #ifndef __packed
-# if LIBBSD_GCC_VERSION >= 0x0207
+# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__packed__)
 #  define __packed __attribute__((__packed__))
 # else
 #  define __packed
 #endif
 
 #ifndef __aligned
-# if LIBBSD_GCC_VERSION >= 0x0207
+# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__aligned__)
 #  define __aligned(x) __attribute__((__aligned__(x)))
 # else
 #  define __aligned(x)
 #endif
 
 #ifndef __printflike
-# if LIBBSD_GCC_VERSION >= 0x0300
+# if LIBBSD_GCC_VERSION >= 0x0300 || __has_attribute(__format__)
 #  define __printflike(x, y) __attribute((__format__(__printf__, (x), (y))))
 # else
 #  define __printflike(x, y)
 #endif
 
 #ifndef __nonnull
-# if LIBBSD_GCC_VERSION >= 0x0302
+# if LIBBSD_GCC_VERSION >= 0x0302 || __has_attribute(__nonnull__)
 #  define __nonnull(x) __attribute__((__nonnull__(x)))
 # else
 #  define __nonnull(x)
  * require it.
  */
 #ifndef __offsetof
-# if LIBBSD_GCC_VERSION >= 0x0401
+# if LIBBSD_GCC_VERSION >= 0x0401 || !__is_identifier(__builtin_offsetof)
 #  define __offsetof(type, field)      __builtin_offsetof(type, field)
 # else
 #  ifndef __cplusplus
  * compatible with member m.
  */
 #ifndef __containerof
-# if LIBBSD_GCC_VERSION >= 0x0301
+# if LIBBSD_GCC_VERSION >= 0x0301 || !__is_identifier(__typeof__)
 #  define __containerof(x, s, m) ({ \
        const volatile __typeof__(((s *)0)->m) *__x = (x); \
        __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m)); \
index c6f89c378c2631b04182df4df2d41dc97bc9f562..1a7b72f09b50a21c6b5771a2ba6a3a8f3351b539 100644 (file)
 
 #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
-#else                          /* __GNUC__ || _MSC_VER */
+#else                          /* __GNUC__ || __clang__ || _MSC_VER */
 #define inline
-#endif                         /* !__GNUC__ && !_MSC_VER */
+#endif                         /* !__GNUC__ && !__clang__ && !_MSC_VER */
 
 #define KEYSZ  32
 #define IVSZ   8