Skip to content

Commit

Permalink
Use __builtin_unreachable() directly in ZEND_UNREACHABLE
Browse files Browse the repository at this point in the history
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
  • Loading branch information
iluuu1994 committed Sep 20, 2023
1 parent 186a07f commit 37ce719
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Zend/zend_portability.h
Expand Up @@ -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; */
Expand Down

0 comments on commit 37ce719

Please sign in to comment.