diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h index 55adba48b02c0..7721e7d593cfb 100644 --- a/Zend/zend_portability.h +++ b/Zend/zend_portability.h @@ -92,7 +92,7 @@ #elif defined(__clang__) && __has_builtin(__builtin_assume) # pragma clang diagnostic ignored "-Wassume" # define ZEND_ASSUME(c) __builtin_assume(c) -#elif ((defined(__GNUC__) && ZEND_GCC_VERSION >= 4005) || __has_builtin(__builtin_unreachable)) && PHP_HAVE_BUILTIN_EXPECT +#elif PHP_HAVE_BUILTIN_UNREACHABLE && PHP_HAVE_BUILTIN_EXPECT # define ZEND_ASSUME(c) do { \ if (__builtin_expect(!(c), 0)) __builtin_unreachable(); \ } while (0) @@ -106,12 +106,9 @@ # define ZEND_ASSERT(c) ZEND_ASSUME(c) #endif -#ifdef __has_builtin -# if __has_builtin(__builtin_unreachable) -# define _ZEND_UNREACHABLE() __builtin_unreachable() -# endif -#endif -#ifndef _ZEND_UNREACHABLE +#ifdef PHP_HAVE_BUILTIN_UNREACHABLE +# define _ZEND_UNREACHABLE() __builtin_unreachable() +#else # define _ZEND_UNREACHABLE() ZEND_ASSUME(0) #endif diff --git a/build/php.m4 b/build/php.m4 index 80b20410b1818..e66451fccc891 100644 --- a/build/php.m4 +++ b/build/php.m4 @@ -2464,6 +2464,25 @@ AC_DEFUN([PHP_CHECK_BUILTIN_EXPECT], [ AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_EXPECT], [$have_builtin_expect], [Whether the compiler supports __builtin_expect]) ]) +dnl +dnl PHP_CHECK_BUILTIN_UNREACHABLE +dnl +AC_DEFUN([PHP_CHECK_BUILTIN_UNREACHABLE], [ + AC_MSG_CHECKING([for __builtin_unreachable]) + + AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[ + __builtin_unreachable(); + ]])], [ + have_builtin_unreachable=1 + AC_MSG_RESULT([yes]) + ], [ + have_builtin_unreachable=0 + AC_MSG_RESULT([no]) + ]) + + AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_UNREACHABLE], [$have_builtin_unreachable], [Whether the compiler supports __builtin_unreachable]) +]) + dnl dnl PHP_CHECK_BUILTIN_CLZ dnl diff --git a/configure.ac b/configure.ac index 38a37a28bafe5..8079d98d21d4e 100644 --- a/configure.ac +++ b/configure.ac @@ -494,6 +494,8 @@ PHP_CHECK_STDINT_TYPES dnl Check __builtin_expect PHP_CHECK_BUILTIN_EXPECT +dnl Check __builtin_unreachable +PHP_CHECK_BUILTIN_UNREACHABLE dnl Check __builtin_clz PHP_CHECK_BUILTIN_CLZ dnl Check __builtin_clzl