From bbe742eddf9a4587307f54e2058d1f7a9faf4078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 16 Feb 2026 14:21:55 +0100 Subject: [PATCH 1/2] tree-wide: Replace `ZEND_STATIC_ASSERT()` by `static_assert()` --- Zend/zend_compile.c | 2 +- Zend/zend_compile.h | 2 +- Zend/zend_execute.h | 2 +- ext/date/time_duration.c | 4 ++-- ext/random/engine_mt19937.c | 2 +- ext/random/php_random_zend_utils.h | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index bad60a5f1071..8d65f1e91394 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5944,7 +5944,7 @@ static void zend_compile_static_var_common(zend_string *var_name, zval *value, u opline->op1_type = IS_CV; opline->op1.var = lookup_cv(var_name); - ZEND_STATIC_ASSERT(sizeof(Bucket) % 8 == 0, "Bucket size not compatible with storing flags in lower three bits"); + static_assert(sizeof(Bucket) % 8 == 0, "Bucket size not compatible with storing flags in lower three bits"); opline->extended_value = (uint32_t)((char*)value - (char*)CG(active_op_array)->static_variables->arData) | mode; } /* }}} */ diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 6502770a2662..ec6d8b09bbe7 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -713,7 +713,7 @@ struct _zend_execute_data { (call)->This.u2.num_args /* Ensure the correct alignment before slots calculation */ -ZEND_STATIC_ASSERT(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval), +static_assert(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval), "zval must be aligned by ZEND_MM_ALIGNMENT"); /* A number of call frame slots (zvals) reserved for zend_execute_data. */ #define ZEND_CALL_FRAME_SLOT \ diff --git a/Zend/zend_execute.h b/Zend/zend_execute.h index 2250a873af29..f7679d920d21 100644 --- a/Zend/zend_execute.h +++ b/Zend/zend_execute.h @@ -295,7 +295,7 @@ struct _zend_vm_stack { }; /* Ensure the correct alignment before slots calculation */ -ZEND_STATIC_ASSERT(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval), +static_assert(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval), "zval must be aligned by ZEND_MM_ALIGNMENT"); /* A number of call frame slots (zvals) reserved for _zend_vm_stack. */ #define ZEND_VM_STACK_HEADER_SLOTS \ diff --git a/ext/date/time_duration.c b/ext/date/time_duration.c index a9f69db7a3d8..f84bee1fc72e 100644 --- a/ext/date/time_duration.c +++ b/ext/date/time_duration.c @@ -25,8 +25,8 @@ #define NANOS_IN_MILLI 1000000 #define MILLIS_IN_SEC 1000 -ZEND_STATIC_ASSERT(NANOS_IN_MICRO * MICROS_IN_SEC == NANOS_IN_SEC, ""); -ZEND_STATIC_ASSERT(NANOS_IN_MILLI * MILLIS_IN_SEC == NANOS_IN_SEC, ""); +static_assert(NANOS_IN_MICRO * MICROS_IN_SEC == NANOS_IN_SEC, ""); +static_assert(NANOS_IN_MILLI * MILLIS_IN_SEC == NANOS_IN_SEC, ""); #define Z_PARAM_ULONG(l) { \ zend_long __##l; \ diff --git a/ext/random/engine_mt19937.c b/ext/random/engine_mt19937.c index a84fb9585c80..bccf3770fb43 100644 --- a/ext/random/engine_mt19937.c +++ b/ext/random/engine_mt19937.c @@ -85,7 +85,7 @@ */ #define N 624 /* length of state vector */ -ZEND_STATIC_ASSERT( +static_assert( N == sizeof(((php_random_status_state_mt19937*)0)->state) / sizeof(((php_random_status_state_mt19937*)0)->state[0]), "Assumed length of Mt19937 state vector does not match actual size." ); diff --git a/ext/random/php_random_zend_utils.h b/ext/random/php_random_zend_utils.h index 56718e5c214b..411da02a075c 100644 --- a/ext/random/php_random_zend_utils.h +++ b/ext/random/php_random_zend_utils.h @@ -25,7 +25,7 @@ typedef struct php_random_bytes_insecure_state_for_zend { php_random_status_state_xoshiro256starstar xoshiro256starstar_state; } php_random_bytes_insecure_state_for_zend; -ZEND_STATIC_ASSERT(sizeof(zend_random_bytes_insecure_state) >= sizeof(php_random_bytes_insecure_state_for_zend), ""); +static_assert(sizeof(zend_random_bytes_insecure_state) >= sizeof(php_random_bytes_insecure_state_for_zend), ""); ZEND_ATTRIBUTE_NONNULL PHPAPI void php_random_bytes_insecure_for_zend( zend_random_bytes_insecure_state *state, void *bytes, size_t size); From 1c45142f7017a6463eaa690be71c397a24cae1e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 16 Feb 2026 14:22:24 +0100 Subject: [PATCH 2/2] zend_portability: Remove `ZEND_STATIC_ASSERT()` --- UPGRADING.INTERNALS | 1 + Zend/zend_portability.h | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index 57e1ab63be8a..4b5eed39a7b5 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -16,6 +16,7 @@ PHP 8.7 INTERNALS UPGRADE NOTES - Removed zend_execute_scripts(). Manually call zend_execute_script() in a loop instead. +- Removed ZEND_STATIC_ASSERT(). Use C11 static_assert() directly instead. ======================== 2. Build system changes diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h index ccad24682fdb..03543045bfde 100644 --- a/Zend/zend_portability.h +++ b/Zend/zend_portability.h @@ -862,14 +862,6 @@ extern "C++" { /** @deprecated */ #define ZEND_CGG_DIAGNOSTIC_IGNORED_END ZEND_DIAGNOSTIC_IGNORED_END -#if defined(__cplusplus) -# define ZEND_STATIC_ASSERT(c, m) static_assert((c), m) -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */ -# define ZEND_STATIC_ASSERT(c, m) _Static_assert((c), m) -#else -# define ZEND_STATIC_ASSERT(c, m) -#endif - #if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) /* C11 */ \ || (defined(__cplusplus) && __cplusplus >= 201103L) /* C++11 */) && !defined(ZEND_WIN32) typedef max_align_t zend_max_align_t;