Skip to content

Commit 2bd6579

Browse files
authored
Check for __has_attribute(x) and/or clang instead of only basing existence on ZEND_GCC_VERSION (#21622)
1 parent 42162bd commit 2bd6579

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

Zend/zend_cpuinfo.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ static zend_always_inline int zend_cpu_supports_avx512_vbmi(void) {
271271
}
272272
#endif
273273

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

289-
/* __builtin_cpu_supports has cldemote from gcc11 */
290-
#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)
289+
/* __builtin_cpu_supports has cldemote from gcc11 and clang 19 */
290+
#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && ((defined(__clang__) && (__clang_major__ >= 19)) || (!defined(__clang__) && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)))
291+
#define HAVE_ZEND_CPU_SUPPORTS_CLDEMOTE 1
291292
ZEND_NO_SANITIZE_ADDRESS
292293
static inline int zend_cpu_supports_cldemote(void) {
293294
#ifdef PHP_HAVE_BUILTIN_CPU_INIT

Zend/zend_portability.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ char *alloca();
270270
# define ZEND_ATTRIBUTE_NODISCARD
271271
#endif
272272

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

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

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

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

679679
/* Do not use for conditional declaration of API functions! */
680-
#if defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000))
681-
/* __builtin_cpu_supports has pclmul from gcc9 */
680+
#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))
681+
/* __builtin_cpu_supports has pclmul from gcc9 and clang 19 */
682682
# define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PROTO 1
683683
#elif defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER)
684684
# define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PTR 1

ext/opcache/jit/zend_jit_ir.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
+----------------------------------------------------------------------+
1515
*/
1616

17+
#include "Zend/zend_cpuinfo.h"
1718
#include "Zend/zend_types.h"
1819
#include "Zend/zend_type_info.h"
1920
#include "jit/ir/ir.h"
@@ -3394,7 +3395,7 @@ static void zend_jit_setup(bool reattached)
33943395
if (zend_cpu_supports_avx()) {
33953396
allowed_opt_flags |= ZEND_JIT_CPU_AVX;
33963397
}
3397-
# if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)
3398+
# ifdef HAVE_ZEND_CPU_SUPPORTS_CLDEMOTE
33983399
if (zend_cpu_supports_cldemote()) {
33993400
default_mflags |= IR_X86_CLDEMOTE;
34003401
}

ext/opcache/zend_shared_alloc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ typedef union _align_test {
164164
zend_long lng;
165165
} align_test;
166166

167-
#if ZEND_GCC_VERSION >= 2000
167+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
168+
# define PLATFORM_ALIGNMENT (alignof(align_test) < 8 ? 8 : alignof(align_test))
169+
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
170+
# define PLATFORM_ALIGNMENT (_Alignof(align_test) < 8 ? 8 : _Alignof(align_test))
171+
#elif ZEND_GCC_VERSION >= 2000 || defined(__clang__)
168172
# define PLATFORM_ALIGNMENT (__alignof__(align_test) < 8 ? 8 : __alignof__(align_test))
169173
#else
170174
# define PLATFORM_ALIGNMENT (sizeof(align_test))

0 commit comments

Comments
 (0)