Use __builtin_unreachable() directly in ZEND_UNREACHABLE

ZEND_UNREACHABLE() currently expands to the following in GCC:

    if (__builtin_expect(!(0), 0)) __builtin_unreachable();

Even though the branch is always executed, GCC does not recognize the outer
branch as unreachable. Removing the if fixes some unexpected warnings.

Closes GH-12248
This commit is contained in:
Ilija Tovilo 2023-09-20 12:33:34 +02:00
parent 186a07f044
commit 37ce7199f2
No known key found for this signature in database
GPG key ID: A4F5D403F118200A

View file

@ -106,10 +106,19 @@
# 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
# define _ZEND_UNREACHABLE() ZEND_ASSUME(0)
#endif
#if ZEND_DEBUG
# define ZEND_UNREACHABLE() do {ZEND_ASSERT(0); ZEND_ASSUME(0);} while (0)
# define ZEND_UNREACHABLE() do {ZEND_ASSERT(0); _ZEND_UNREACHABLE();} while (0)
#else
# define ZEND_UNREACHABLE() ZEND_ASSUME(0)
# define ZEND_UNREACHABLE() _ZEND_UNREACHABLE()
#endif
/* pseudo fallthrough keyword; */