Skip to content

Use autoconf for recognizing __builtin_unreachable() #12266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions Zend/zend_portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
19 changes: 19 additions & 0 deletions build/php.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down