Skip to content

Commit 62e2402

Browse files
authored
Use autoconf for recognizing __builtin_unreachable() (php#12266)
Older versions of GCC don't support __has_builtin(), but do support __builtin_unreachable().
1 parent 77bc5aa commit 62e2402

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

Zend/zend_portability.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
#elif defined(__clang__) && __has_builtin(__builtin_assume)
9393
# pragma clang diagnostic ignored "-Wassume"
9494
# define ZEND_ASSUME(c) __builtin_assume(c)
95-
#elif ((defined(__GNUC__) && ZEND_GCC_VERSION >= 4005) || __has_builtin(__builtin_unreachable)) && PHP_HAVE_BUILTIN_EXPECT
95+
#elif PHP_HAVE_BUILTIN_UNREACHABLE && PHP_HAVE_BUILTIN_EXPECT
9696
# define ZEND_ASSUME(c) do { \
9797
if (__builtin_expect(!(c), 0)) __builtin_unreachable(); \
9898
} while (0)
@@ -106,12 +106,9 @@
106106
# define ZEND_ASSERT(c) ZEND_ASSUME(c)
107107
#endif
108108

109-
#ifdef __has_builtin
110-
# if __has_builtin(__builtin_unreachable)
111-
# define _ZEND_UNREACHABLE() __builtin_unreachable()
112-
# endif
113-
#endif
114-
#ifndef _ZEND_UNREACHABLE
109+
#ifdef PHP_HAVE_BUILTIN_UNREACHABLE
110+
# define _ZEND_UNREACHABLE() __builtin_unreachable()
111+
#else
115112
# define _ZEND_UNREACHABLE() ZEND_ASSUME(0)
116113
#endif
117114

build/php.m4

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,25 @@ AC_DEFUN([PHP_CHECK_BUILTIN_EXPECT], [
24642464
AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_EXPECT], [$have_builtin_expect], [Whether the compiler supports __builtin_expect])
24652465
])
24662466

2467+
dnl
2468+
dnl PHP_CHECK_BUILTIN_UNREACHABLE
2469+
dnl
2470+
AC_DEFUN([PHP_CHECK_BUILTIN_UNREACHABLE], [
2471+
AC_MSG_CHECKING([for __builtin_unreachable])
2472+
2473+
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2474+
__builtin_unreachable();
2475+
]])], [
2476+
have_builtin_unreachable=1
2477+
AC_MSG_RESULT([yes])
2478+
], [
2479+
have_builtin_unreachable=0
2480+
AC_MSG_RESULT([no])
2481+
])
2482+
2483+
AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_UNREACHABLE], [$have_builtin_unreachable], [Whether the compiler supports __builtin_unreachable])
2484+
])
2485+
24672486
dnl
24682487
dnl PHP_CHECK_BUILTIN_CLZ
24692488
dnl

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ PHP_CHECK_STDINT_TYPES
494494

495495
dnl Check __builtin_expect
496496
PHP_CHECK_BUILTIN_EXPECT
497+
dnl Check __builtin_unreachable
498+
PHP_CHECK_BUILTIN_UNREACHABLE
497499
dnl Check __builtin_clz
498500
PHP_CHECK_BUILTIN_CLZ
499501
dnl Check __builtin_clzl

0 commit comments

Comments
 (0)