diff --git a/config/HDFTests.c b/config/HDFTests.c index 33135f1a04e..f7ab8d916ce 100644 --- a/config/HDFTests.c +++ b/config/HDFTests.c @@ -27,21 +27,6 @@ main () #endif /* HAVE___FLOAT128 */ -#ifdef HAVE_BUILTIN_EXPECT - -int -main () -{ - void *ptr = (void*) 0; - - if (__builtin_expect (ptr != (void*) 0, 1)) - return 0; - - return 0; -} - -#endif /* HAVE_BUILTIN_EXPECT */ - #ifdef HAVE_ATTRIBUTE int diff --git a/src/H5pubconf.h.in b/src/H5pubconf.h.in index 9a87433e6b0..93b28b5327f 100644 --- a/src/H5pubconf.h.in +++ b/src/H5pubconf.h.in @@ -307,9 +307,6 @@ /* Define to 1 if you have the header file. */ #cmakedefine H5_HAVE_SZLIB_H @H5_HAVE_SZLIB_H@ -/* Define to 1 if the compiler supports the __builtin_expect() extension */ -#cmakedefine H5_HAVE_BUILTIN_EXPECT @H5_HAVE_BUILTIN_EXPECT@ - /* Define if we have thread support */ # cmakedefine H5_HAVE_THREADS @H5_HAVE_THREADS@ diff --git a/src/H5public.h b/src/H5public.h index dfad2b2d511..09c46e15f8e 100644 --- a/src/H5public.h +++ b/src/H5public.h @@ -461,6 +461,22 @@ typedef void (*H5_atclose_func_t)(void *ctx); * Does the compiler support the __builtin_expect() syntax? * It's not a problem if not. */ + +/* clang-format off */ +#if defined(__has_builtin) + /* clang extension to check for builtins. Do this first, because clang + * also defines __GNUC__ and didn't support __builtin_expect() until + * more recently. + */ +# if __has_builtin(__builtin_expect) +# define H5_HAVE_BUILTIN_EXPECT 1 +# endif +#elif defined(__GNUC__) + /* __builtin_expect() has been supported since 2.95 or 2.96 (circa 2000) */ +# define H5_HAVE_BUILTIN_EXPECT 1 +#endif +/* clang-format on */ + #if H5_HAVE_BUILTIN_EXPECT #define H5_LIKELY(expression) __builtin_expect(!!(expression), 1) #define H5_UNLIKELY(expression) __builtin_expect(!!(expression), 0)