From 37ce7199f2b7cc89c564376f1cc652d0b93da60d Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 20 Sep 2023 12:33:34 +0200 Subject: [PATCH] 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 --- Zend/zend_portability.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h index c098d29d518..55adba48b02 100644 --- a/Zend/zend_portability.h +++ b/Zend/zend_portability.h @@ -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; */