Skip to content

Commit 355571c

Browse files
authored
Fix usage of optimize attribute on unsupported compilers (GH-21819)
Clang supports __has_attribute(cold) but not __attribute__((optimize(...))). The cold and optimize branches need to be split.
1 parent 61eb31a commit 355571c

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Zend/zend_portability.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,14 @@ char *alloca();
314314

315315
#if (defined(__GNUC__) && ZEND_GCC_VERSION >= 4003) || __has_attribute(cold)
316316
# define ZEND_COLD __attribute__((cold))
317-
# ifdef __OPTIMIZE__
318-
# define ZEND_OPT_SIZE __attribute__((optimize("Os")))
319-
# define ZEND_OPT_SPEED __attribute__((optimize("Ofast")))
320-
# else
321-
# define ZEND_OPT_SIZE
322-
# define ZEND_OPT_SPEED
323-
# endif
324317
#else
325318
# define ZEND_COLD
319+
#endif
320+
321+
#if ((defined(__GNUC__) && ZEND_GCC_VERSION >= 4003) || __has_attribute(optimize)) && defined(__OPTIMIZE__)
322+
# define ZEND_OPT_SIZE __attribute__((optimize("Os")))
323+
# define ZEND_OPT_SPEED __attribute__((optimize("Ofast")))
324+
#else
326325
# define ZEND_OPT_SIZE
327326
# define ZEND_OPT_SPEED
328327
#endif

0 commit comments

Comments
 (0)