Commit 2bd6579e56b for php.net

commit 2bd6579e56b59883189b1df6ba411c734104502d
Author: Marc <m@pyc.ac>
Date:   Mon Apr 20 20:32:04 2026 +0700

    Check for __has_attribute(x) and/or clang instead of only basing existence on ZEND_GCC_VERSION (#21622)

diff --git a/Zend/zend_cpuinfo.h b/Zend/zend_cpuinfo.h
index 2290a702475..513dacfd08f 100644
--- a/Zend/zend_cpuinfo.h
+++ b/Zend/zend_cpuinfo.h
@@ -271,8 +271,8 @@ static zend_always_inline int zend_cpu_supports_avx512_vbmi(void) {
 }
 #endif

-/* __builtin_cpu_supports has pclmul from gcc9 */
-#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000))
+/* __builtin_cpu_supports has pclmul from gcc9 and clang 19 */
+#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && (!defined(__GNUC__) || (defined(__clang__) && __clang_major__ >= 19) || (ZEND_GCC_VERSION >= 9000))
 ZEND_NO_SANITIZE_ADDRESS
 static inline int zend_cpu_supports_pclmul(void) {
 #ifdef PHP_HAVE_BUILTIN_CPU_INIT
@@ -286,8 +286,9 @@ static inline int zend_cpu_supports_pclmul(void) {
 }
 #endif

-/* __builtin_cpu_supports has cldemote from gcc11 */
-#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)
+/* __builtin_cpu_supports has cldemote from gcc11 and clang 19 */
+#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && ((defined(__clang__) && (__clang_major__ >= 19)) || (!defined(__clang__) && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)))
+#define HAVE_ZEND_CPU_SUPPORTS_CLDEMOTE 1
 ZEND_NO_SANITIZE_ADDRESS
 static inline int zend_cpu_supports_cldemote(void) {
 #ifdef PHP_HAVE_BUILTIN_CPU_INIT
diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h
index e4d90058a69..6801131e41d 100644
--- a/Zend/zend_portability.h
+++ b/Zend/zend_portability.h
@@ -270,7 +270,7 @@ char *alloca();
 # define ZEND_ATTRIBUTE_NODISCARD
 #endif

-#if ZEND_GCC_VERSION >= 3000
+#if ZEND_GCC_VERSION >= 3000 || __has_attribute(const)
 # define ZEND_ATTRIBUTE_CONST __attribute__((const))
 #else
 # define ZEND_ATTRIBUTE_CONST
@@ -312,7 +312,7 @@ char *alloca();
 # define ZEND_ATTRIBUTE_NONNULL_ARGS(...)
 #endif

-#if defined(__GNUC__) && ZEND_GCC_VERSION >= 4003
+#if (defined(__GNUC__) && ZEND_GCC_VERSION >= 4003) || __has_attribute(cold)
 # define ZEND_COLD __attribute__((cold))
 # ifdef __OPTIMIZE__
 #  define ZEND_OPT_SIZE  __attribute__((optimize("Os")))
@@ -327,7 +327,7 @@ char *alloca();
 # define ZEND_OPT_SPEED
 #endif

-#if defined(__GNUC__) && ZEND_GCC_VERSION >= 5000
+#if (defined(__GNUC__) && ZEND_GCC_VERSION >= 5000)
 # define ZEND_ATTRIBUTE_UNUSED_LABEL __attribute__((unused));
 # define ZEND_ATTRIBUTE_COLD_LABEL __attribute__((cold));
 #else
@@ -651,8 +651,8 @@ extern "C++" {
 #endif

 /* Do not use for conditional declaration of API functions! */
-#if defined(ZEND_INTRIN_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000))
-/* __builtin_cpu_supports has pclmul from gcc9 */
+#if defined(ZEND_INTRIN_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (!defined(__GNUC__) || (defined(__clang__) && __clang_major__ >= 19) || (ZEND_GCC_VERSION >= 9000))
+/* __builtin_cpu_supports has pclmul from gcc9 and clang 19 */
 # define ZEND_INTRIN_PCLMUL_FUNC_PROTO 1
 #elif defined(ZEND_INTRIN_PCLMUL_RESOLVER)
 # define ZEND_INTRIN_PCLMUL_FUNC_PTR 1
@@ -677,8 +677,8 @@ extern "C++" {
 #endif

 /* Do not use for conditional declaration of API functions! */
-#if defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000))
-/* __builtin_cpu_supports has pclmul from gcc9 */
+#if defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (!defined(__GNUC__) || (defined(__clang__) && __clang_major__ >= 19) || (ZEND_GCC_VERSION >= 9000))
+/* __builtin_cpu_supports has pclmul from gcc9 and clang 19 */
 # define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PROTO 1
 #elif defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER)
 # define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PTR 1
diff --git a/ext/opcache/jit/zend_jit_ir.c b/ext/opcache/jit/zend_jit_ir.c
index 2461d024dd6..c4b88b74f64 100644
--- a/ext/opcache/jit/zend_jit_ir.c
+++ b/ext/opcache/jit/zend_jit_ir.c
@@ -14,6 +14,7 @@
    +----------------------------------------------------------------------+
 */

+#include "Zend/zend_cpuinfo.h"
 #include "Zend/zend_types.h"
 #include "Zend/zend_type_info.h"
 #include "jit/ir/ir.h"
@@ -3394,7 +3395,7 @@ static void zend_jit_setup(bool reattached)
 	if (zend_cpu_supports_avx()) {
 		allowed_opt_flags |= ZEND_JIT_CPU_AVX;
 	}
-# if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)
+# ifdef HAVE_ZEND_CPU_SUPPORTS_CLDEMOTE
 	if (zend_cpu_supports_cldemote()) {
 		default_mflags |= IR_X86_CLDEMOTE;
 	}
diff --git a/ext/opcache/zend_shared_alloc.h b/ext/opcache/zend_shared_alloc.h
index 23d515f5b9f..cf0bb10d893 100644
--- a/ext/opcache/zend_shared_alloc.h
+++ b/ext/opcache/zend_shared_alloc.h
@@ -164,7 +164,11 @@ typedef union _align_test {
 	zend_long  lng;
 } align_test;

-#if ZEND_GCC_VERSION >= 2000
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
+# define PLATFORM_ALIGNMENT (alignof(align_test) < 8 ? 8 : alignof(align_test))
+#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+# define PLATFORM_ALIGNMENT (_Alignof(align_test) < 8 ? 8 : _Alignof(align_test))
+#elif ZEND_GCC_VERSION >= 2000 || defined(__clang__)
 # define PLATFORM_ALIGNMENT (__alignof__(align_test) < 8 ? 8 : __alignof__(align_test))
 #else
 # define PLATFORM_ALIGNMENT (sizeof(align_test))