Skip to content

Commit 37ce719

Browse files
committedSep 20, 2023
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
1 parent 186a07f commit 37ce719

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed
 

‎Zend/zend_portability.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,19 @@
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
115+
# define _ZEND_UNREACHABLE() ZEND_ASSUME(0)
116+
#endif
117+
109118
#if ZEND_DEBUG
110-
# define ZEND_UNREACHABLE() do {ZEND_ASSERT(0); ZEND_ASSUME(0);} while (0)
119+
# define ZEND_UNREACHABLE() do {ZEND_ASSERT(0); _ZEND_UNREACHABLE();} while (0)
111120
#else
112-
# define ZEND_UNREACHABLE() ZEND_ASSUME(0)
121+
# define ZEND_UNREACHABLE() _ZEND_UNREACHABLE()
113122
#endif
114123

115124
/* pseudo fallthrough keyword; */

0 commit comments

Comments
 (0)