From bf4ec8bd9d9d30713a9d3294b946084a6e9e088a Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Tue, 16 Jan 2024 22:41:21 +0100 Subject: [PATCH] Use __attribute__((assume())) in ZEND_ASSUME when available Closes GH-13171 --- Zend/zend_portability.h | 3 +++ sapi/phpdbg/phpdbg_watch.c | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h index 37449d2db3f..945f4a1e271 100644 --- a/Zend/zend_portability.h +++ b/Zend/zend_portability.h @@ -89,6 +89,9 @@ #if defined(ZEND_WIN32) && !defined(__clang__) # define ZEND_ASSUME(c) __assume(c) +#elif defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 13 +/* GCC emits a warning when __attribute__ appears directly after a label, so we need a do-while loop. */ +# define ZEND_ASSUME(c) do { __attribute__((assume(c))); } while (0) #elif defined(__clang__) && __has_builtin(__builtin_assume) # pragma clang diagnostic ignored "-Wassume" # define ZEND_ASSUME(c) __builtin_assume(c) diff --git a/sapi/phpdbg/phpdbg_watch.c b/sapi/phpdbg/phpdbg_watch.c index d4af608ff76..b344c3df355 100644 --- a/sapi/phpdbg/phpdbg_watch.c +++ b/sapi/phpdbg/phpdbg_watch.c @@ -333,8 +333,10 @@ void *phpdbg_watchpoint_userfaultfd_thread(void *phpdbg_globals) { /* ### REGISTER WATCHPOINT ### To be used only by watch element and collision managers ### */ static inline void phpdbg_store_watchpoint_btree(phpdbg_watchpoint_t *watch) { - phpdbg_btree_result *res; - ZEND_ASSERT((res = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong) watch->addr.ptr)) == NULL || res->ptr == watch); +#if ZEND_DEBUG + phpdbg_btree_result *res = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong) watch->addr.ptr); + ZEND_ASSERT(res == NULL || res->ptr == watch); +#endif phpdbg_btree_insert(&PHPDBG_G(watchpoint_tree), (zend_ulong) watch->addr.ptr, watch); }