Skip to content

Commit 99c5aa3

Browse files
committed
check for __has_attribute(x) instead of only basing existence on ZEND_GCC_VERSION
1 parent 3619caa commit 99c5aa3

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

Zend/zend_cpuinfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static zend_always_inline int zend_cpu_supports_avx512_vbmi(void) {
273273
#endif
274274

275275
/* __builtin_cpu_supports has pclmul from gcc9 */
276-
#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000))
276+
#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && (!defined(__GNUC__) || defined(__clang__) || (ZEND_GCC_VERSION >= 9000))
277277
ZEND_NO_SANITIZE_ADDRESS
278278
static inline int zend_cpu_supports_pclmul(void) {
279279
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
@@ -287,8 +287,8 @@ static inline int zend_cpu_supports_pclmul(void) {
287287
}
288288
#endif
289289

290-
/* __builtin_cpu_supports has cldemote from gcc11 */
291-
#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)
290+
/* __builtin_cpu_supports has cldemote from gcc11 and clang 19 */
291+
#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && ((defined(__clang__) && (__clang_major__ >= 19)) || (!defined(__clang__) && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)))
292292
ZEND_NO_SANITIZE_ADDRESS
293293
static inline int zend_cpu_supports_cldemote(void) {
294294
#ifdef PHP_HAVE_BUILTIN_CPU_INIT

Zend/zend_portability.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ char *alloca();
272272
# define ZEND_ATTRIBUTE_NODISCARD
273273
#endif
274274

275-
#if ZEND_GCC_VERSION >= 3000
275+
#if ZEND_GCC_VERSION >= 3000 || __has_attribute(const)
276276
# define ZEND_ATTRIBUTE_CONST __attribute__((const))
277277
#else
278278
# define ZEND_ATTRIBUTE_CONST
@@ -314,7 +314,7 @@ char *alloca();
314314
# define ZEND_ATTRIBUTE_NONNULL_ARGS(...)
315315
#endif
316316

317-
#if defined(__GNUC__) && ZEND_GCC_VERSION >= 4003
317+
#if (defined(__GNUC__) && ZEND_GCC_VERSION >= 4003) || __has_attribute(cold)
318318
# define ZEND_COLD __attribute__((cold))
319319
# ifdef __OPTIMIZE__
320320
# define ZEND_OPT_SIZE __attribute__((optimize("Os")))
@@ -329,7 +329,7 @@ char *alloca();
329329
# define ZEND_OPT_SPEED
330330
#endif
331331

332-
#if defined(__GNUC__) && ZEND_GCC_VERSION >= 5000
332+
#if (defined(__GNUC__) && ZEND_GCC_VERSION >= 5000) || (__has_attribute(unused) && __has_attribute(cold))
333333
# define ZEND_ATTRIBUTE_UNUSED_LABEL __attribute__((unused));
334334
# define ZEND_ATTRIBUTE_COLD_LABEL __attribute__((cold));
335335
#else
@@ -653,7 +653,7 @@ extern "C++" {
653653
#endif
654654

655655
/* Do not use for conditional declaration of API functions! */
656-
#if defined(ZEND_INTRIN_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000))
656+
#if defined(ZEND_INTRIN_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (!defined(__GNUC__) || defined(__clang__) || (ZEND_GCC_VERSION >= 9000))
657657
/* __builtin_cpu_supports has pclmul from gcc9 */
658658
# define ZEND_INTRIN_PCLMUL_FUNC_PROTO 1
659659
#elif defined(ZEND_INTRIN_PCLMUL_RESOLVER)
@@ -679,7 +679,7 @@ extern "C++" {
679679
#endif
680680

681681
/* Do not use for conditional declaration of API functions! */
682-
#if defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000))
682+
#if defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (!defined(__GNUC__) || defined(__clang__) || (ZEND_GCC_VERSION >= 9000))
683683
/* __builtin_cpu_supports has pclmul from gcc9 */
684684
# define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PROTO 1
685685
#elif defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER)

ext/opcache/jit/zend_jit_ir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3396,7 +3396,7 @@ static void zend_jit_setup(bool reattached)
33963396
if (zend_cpu_supports_avx()) {
33973397
allowed_opt_flags |= ZEND_JIT_CPU_AVX;
33983398
}
3399-
# if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)
3399+
# if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && ((defined(__clang__) && (__clang_major__ >= 19)) || (!defined(__clang__) && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)))
34003400
if (zend_cpu_supports_cldemote()) {
34013401
default_mflags |= IR_X86_CLDEMOTE;
34023402
}

ext/opcache/zend_shared_alloc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ typedef union _align_test {
166166
zend_long lng;
167167
} align_test;
168168

169-
#if ZEND_GCC_VERSION >= 2000
169+
#if ZEND_GCC_VERSION >= 2000 || defined(__clang__)
170170
# define PLATFORM_ALIGNMENT (__alignof__(align_test) < 8 ? 8 : __alignof__(align_test))
171171
#else
172172
# define PLATFORM_ALIGNMENT (sizeof(align_test))

0 commit comments

Comments
 (0)