Skip to content

Commit f9f5766

Browse files
committed
Sync CS and simplify strlen() optimization bug check
This syncs CS a bit forward with prefixing cache variables related to checks with `PHP_HAS_`. Knowing GNU C compiler version is sufficient for this issue. Also, GCC version 8.2 is becoming rare these days (considering that this was fixed in 8.3).
1 parent 3e4e4c2 commit f9f5766

File tree

4 files changed

+91
-163
lines changed

4 files changed

+91
-163
lines changed

cmake/cmake/Flags.cmake

Lines changed: 74 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^alpha")
1919
endif()
2020
endif()
2121

22-
# Check for broken GCC optimize-strlen.
23-
include(PHP/CheckBrokenGccStrlenOpt)
24-
if(PHP_HAVE_BROKEN_OPTIMIZE_STRLEN)
25-
php_check_compiler_flag(C -fno-optimize-strlen HAVE_FNO_OPTIMIZE_STRLEN_C)
26-
if(HAVE_FNO_OPTIMIZE_STRLEN_C)
22+
# Check if GCC has broken strlen() optimization. Early GCC 8 versions shipped
23+
# with a strlen() optimization bug, so it didn't properly handle the
24+
# 'char val[1]' struct hack. Fixed in GCC 8.3. If below check is successful the
25+
# '-fno-optimize-strlen' compiler flag should be added.
26+
# See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86914
27+
if(
28+
CMAKE_C_COMPILER_ID STREQUAL "GNU"
29+
AND DEFINED CMAKE_C_COMPILER_VERSION
30+
AND CMAKE_C_COMPILER_VERSION VERSION_LESS 8.3
31+
)
32+
php_check_compiler_flag(C -fno-optimize-strlen PHP_HAS_FNO_OPTIMIZE_STRLEN_C)
33+
if(PHP_HAS_FNO_OPTIMIZE_STRLEN_C)
2734
target_compile_options(
2835
php_config
2936
INTERFACE
@@ -32,28 +39,28 @@ if(PHP_HAVE_BROKEN_OPTIMIZE_STRLEN)
3239
endif()
3340
endif()
3441

35-
php_check_compiler_flag(C -Wno-sign-compare HAVE_WNO_SIGN_COMPARE_C)
42+
php_check_compiler_flag(C -Wno-sign-compare PHP_HAS_WNO_SIGN_COMPARE_C)
3643
if(CXX IN_LIST enabledLanguages)
37-
php_check_compiler_flag(CXX -Wno-sign-compare HAVE_WNO_SIGN_COMPARE_CXX)
44+
php_check_compiler_flag(CXX -Wno-sign-compare PHP_HAS_WNO_SIGN_COMPARE_CXX)
3845
endif()
3946
target_compile_options(
4047
php_config
4148
BEFORE
4249
INTERFACE
43-
$<$<AND:$<BOOL:${HAVE_WNO_SIGN_COMPARE_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wno-sign-compare>
44-
$<$<AND:$<BOOL:${HAVE_WNO_SIGN_COMPARE_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wno-sign-compare>
50+
$<$<AND:$<BOOL:${PHP_HAS_WNO_SIGN_COMPARE_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wno-sign-compare>
51+
$<$<AND:$<BOOL:${PHP_HAS_WNO_SIGN_COMPARE_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wno-sign-compare>
4552
)
4653

47-
php_check_compiler_flag(C -Wno-unused-parameter HAVE_WNO_UNUSED_PARAMETER_C)
54+
php_check_compiler_flag(C -Wno-unused-parameter PHP_HAS_WNO_UNUSED_PARAMETER_C)
4855
if(CXX IN_LIST enabledLanguages)
49-
php_check_compiler_flag(CXX -Wno-unused-parameter HAVE_WNO_UNUSED_PARAMETER_CXX)
56+
php_check_compiler_flag(CXX -Wno-unused-parameter PHP_HAS_WNO_UNUSED_PARAMETER_CXX)
5057
endif()
5158
target_compile_options(
5259
php_config
5360
BEFORE
5461
INTERFACE
55-
$<$<AND:$<BOOL:${HAVE_WNO_UNUSED_PARAMETER_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wno-unused-parameter>
56-
$<$<AND:$<BOOL:${HAVE_WNO_UNUSED_PARAMETER_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wno-unused-parameter>
62+
$<$<AND:$<BOOL:${PHP_HAS_WNO_UNUSED_PARAMETER_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wno-unused-parameter>
63+
$<$<AND:$<BOOL:${PHP_HAS_WNO_UNUSED_PARAMETER_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wno-unused-parameter>
5764
)
5865

5966
if(MSVC)
@@ -73,99 +80,99 @@ else()
7380
endif()
7481

7582
# Check if compiler supports -Wno-clobbered (only GCC).
76-
php_check_compiler_flag(C -Wno-clobbered HAVE_WNO_CLOBBERED_C)
83+
php_check_compiler_flag(C -Wno-clobbered PHP_HAS_WNO_CLOBBERED_C)
7784
if(CXX IN_LIST enabledLanguages)
78-
php_check_compiler_flag(CXX -Wno-clobbered HAVE_WNO_CLOBBERED_CXX)
85+
php_check_compiler_flag(CXX -Wno-clobbered PHP_HAS_WNO_CLOBBERED_CXX)
7986
endif()
8087
target_compile_options(
8188
php_config
8289
BEFORE
8390
INTERFACE
84-
$<$<AND:$<BOOL:${HAVE_WNO_CLOBBERED_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wno-clobbered>
85-
$<$<AND:$<BOOL:${HAVE_WNO_CLOBBERED_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wno-clobbered>
91+
$<$<AND:$<BOOL:${PHP_HAS_WNO_CLOBBERED_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wno-clobbered>
92+
$<$<AND:$<BOOL:${PHP_HAS_WNO_CLOBBERED_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wno-clobbered>
8693
)
8794

8895
# Check for support for implicit fallthrough level 1, also add after previous
8996
# CFLAGS as level 3 is enabled in -Wextra.
9097
php_check_compiler_flag(
9198
C
9299
-Wimplicit-fallthrough=1
93-
HAVE_WIMPLICIT_FALLTHROUGH_1_C
100+
PHP_HAS_WIMPLICIT_FALLTHROUGH_1_C
94101
)
95102
if(CXX IN_LIST enabledLanguages)
96103
php_check_compiler_flag(
97104
CXX
98105
-Wimplicit-fallthrough=1
99-
HAVE_WIMPLICIT_FALLTHROUGH_1_CXX
106+
PHP_HAS_WIMPLICIT_FALLTHROUGH_1_CXX
100107
)
101108
endif()
102109
target_compile_options(
103110
php_config
104111
INTERFACE
105-
$<$<AND:$<BOOL:${HAVE_WIMPLICIT_FALLTHROUGH_1_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wimplicit-fallthrough=1>
106-
$<$<AND:$<BOOL:${HAVE_WIMPLICIT_FALLTHROUGH_1_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wimplicit-fallthrough=1>
112+
$<$<AND:$<BOOL:${PHP_HAS_WIMPLICIT_FALLTHROUGH_1_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wimplicit-fallthrough=1>
113+
$<$<AND:$<BOOL:${PHP_HAS_WIMPLICIT_FALLTHROUGH_1_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wimplicit-fallthrough=1>
107114
)
108115

109-
php_check_compiler_flag(C -Wduplicated-cond HAVE_WDUPLICATED_COND_C)
116+
php_check_compiler_flag(C -Wduplicated-cond PHP_HAS_WDUPLICATED_COND_C)
110117
if(CXX IN_LIST enabledLanguages)
111-
php_check_compiler_flag(CXX -Wduplicated-cond HAVE_WDUPLICATED_COND_CXX)
118+
php_check_compiler_flag(CXX -Wduplicated-cond PHP_HAS_WDUPLICATED_COND_CXX)
112119
endif()
113120
target_compile_options(
114121
php_config
115122
BEFORE
116123
INTERFACE
117-
$<$<AND:$<BOOL:${HAVE_WDUPLICATED_COND_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wduplicated-cond>
118-
$<$<AND:$<BOOL:${HAVE_WDUPLICATED_COND_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wduplicated-cond>
124+
$<$<AND:$<BOOL:${PHP_HAS_WDUPLICATED_COND_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wduplicated-cond>
125+
$<$<AND:$<BOOL:${PHP_HAS_WDUPLICATED_COND_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wduplicated-cond>
119126
)
120127

121-
php_check_compiler_flag(C -Wlogical-op HAVE_WLOGICAL_OP_C)
128+
php_check_compiler_flag(C -Wlogical-op PHP_HAS_WLOGICAL_OP_C)
122129
if(CXX IN_LIST enabledLanguages)
123-
php_check_compiler_flag(CXX -Wlogical-op HAVE_WLOGICAL_OP_CXX)
130+
php_check_compiler_flag(CXX -Wlogical-op PHP_HAS_WLOGICAL_OP_CXX)
124131
endif()
125132
target_compile_options(
126133
php_config
127134
BEFORE
128135
INTERFACE
129-
$<$<AND:$<BOOL:${HAVE_WLOGICAL_OP_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wlogical-op>
130-
$<$<AND:$<BOOL:${HAVE_WLOGICAL_OP_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wlogical-op>
136+
$<$<AND:$<BOOL:${PHP_HAS_WLOGICAL_OP_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wlogical-op>
137+
$<$<AND:$<BOOL:${PHP_HAS_WLOGICAL_OP_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wlogical-op>
131138
)
132139

133-
php_check_compiler_flag(C -Wformat-truncation HAVE_WFORMAT_TRUNCATION_C)
140+
php_check_compiler_flag(C -Wformat-truncation PHP_HAS_WFORMAT_TRUNCATION_C)
134141
if(CXX IN_LIST enabledLanguages)
135-
php_check_compiler_flag(CXX -Wformat-truncation HAVE_WFORMAT_TRUNCATION_CXX)
142+
php_check_compiler_flag(CXX -Wformat-truncation PHP_HAS_WFORMAT_TRUNCATION_CXX)
136143
endif()
137144
target_compile_options(
138145
php_config
139146
BEFORE
140147
INTERFACE
141-
$<$<AND:$<BOOL:${HAVE_WFORMAT_TRUNCATION_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wformat-truncation>
142-
$<$<AND:$<BOOL:${HAVE_WFORMAT_TRUNCATION_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wformat-truncation>
148+
$<$<AND:$<BOOL:${PHP_HAS_WFORMAT_TRUNCATION_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wformat-truncation>
149+
$<$<AND:$<BOOL:${PHP_HAS_WFORMAT_TRUNCATION_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-Wformat-truncation>
143150
)
144151

145-
php_check_compiler_flag(C -Wstrict-prototypes HAVE_WSTRICT_PROTOTYPES_C)
152+
php_check_compiler_flag(C -Wstrict-prototypes PHP_HAS_WSTRICT_PROTOTYPES_C)
146153
target_compile_options(
147154
php_config
148155
BEFORE
149156
INTERFACE
150-
$<$<AND:$<BOOL:${HAVE_WSTRICT_PROTOTYPES_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wstrict-prototypes>
157+
$<$<AND:$<BOOL:${PHP_HAS_WSTRICT_PROTOTYPES_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-Wstrict-prototypes>
151158
)
152159

153-
php_check_compiler_flag(C -fno-common HAVE_FNO_COMMON_C)
160+
php_check_compiler_flag(C -fno-common PHP_HAS_FNO_COMMON_C)
154161
if(CXX IN_LIST enabledLanguages)
155-
php_check_compiler_flag(CXX -fno-common HAVE_FNO_COMMON_CXX)
162+
php_check_compiler_flag(CXX -fno-common PHP_HAS_FNO_COMMON_CXX)
156163
endif()
157164
target_compile_options(
158165
php_config
159166
BEFORE
160167
INTERFACE
161-
$<$<AND:$<BOOL:${HAVE_FNO_COMMON_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-fno-common>
162-
$<$<AND:$<BOOL:${HAVE_FNO_COMMON_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-fno-common>
168+
$<$<AND:$<BOOL:${PHP_HAS_FNO_COMMON_C}>,$<COMPILE_LANGUAGE:ASM,C>>:-fno-common>
169+
$<$<AND:$<BOOL:${PHP_HAS_FNO_COMMON_CXX}>,$<COMPILE_LANGUAGE:CXX>>:-fno-common>
163170
)
164171

165172
# Explicitly disable floating-point expression contraction, even if already done
166173
# by CMAKE_C_STANDARD. See https://github.com/php/php-src/issues/14140
167-
php_check_compiler_flag(C -ffp-contract=off HAVE_FFP_CONTRACT_OFF_C)
168-
if(HAVE_FFP_CONTRACT_OFF_C)
174+
php_check_compiler_flag(C -ffp-contract=off PHP_HAS_FFP_CONTRACT_OFF_C)
175+
if(PHP_HAS_FFP_CONTRACT_OFF_C)
169176
target_compile_options(
170177
php_config
171178
INTERFACE
@@ -198,19 +205,19 @@ if(PHP_MEMORY_SANITIZER)
198205
php_check_compiler_flag(
199206
C
200207
"-fsanitize=memory;-fsanitize-memory-track-origins"
201-
HAVE_MEMORY_SANITIZER_C
208+
PHP_HAS_MEMORY_SANITIZER_C
202209
)
203210

204211
if(CXX IN_LIST enabledLanguages)
205212
php_check_compiler_flag(
206213
CXX
207214
"-fsanitize=memory;-fsanitize-memory-track-origins"
208-
HAVE_MEMORY_SANITIZER_CXX
215+
PHP_HAS_MEMORY_SANITIZER_CXX
209216
)
210217
endif()
211218
cmake_pop_check_state()
212219

213-
if(HAVE_MEMORY_SANITIZER_C OR HAVE_MEMORY_SANITIZER_CXX)
220+
if(PHP_HAS_MEMORY_SANITIZER_C OR PHP_HAS_MEMORY_SANITIZER_CXX)
214221
target_compile_options(
215222
php_config
216223
INTERFACE
@@ -246,13 +253,13 @@ if(PHP_ADDRESS_SANITIZER)
246253
cmake_push_check_state(RESET)
247254
set(CMAKE_REQUIRED_LINK_OPTIONS "-fsanitize=address")
248255

249-
php_check_compiler_flag(C -fsanitize=address HAVE_ADDRESS_SANITIZER_C)
256+
php_check_compiler_flag(C -fsanitize=address PHP_HAS_ADDRESS_SANITIZER_C)
250257
if(CXX IN_LIST enabledLanguages)
251-
php_check_compiler_flag(CXX -fsanitize=address HAVE_ADDRESS_SANITIZER_CXX)
258+
php_check_compiler_flag(CXX -fsanitize=address PHP_HAS_ADDRESS_SANITIZER_CXX)
252259
endif()
253260
cmake_pop_check_state()
254261

255-
if(HAVE_ADDRESS_SANITIZER_C OR HAVE_ADDRESS_SANITIZER_CXX)
262+
if(PHP_HAS_ADDRESS_SANITIZER_C OR PHP_HAS_ADDRESS_SANITIZER_CXX)
256263
target_compile_options(
257264
php_config
258265
INTERFACE
@@ -288,18 +295,18 @@ if(PHP_UNDEFINED_SANITIZER)
288295
php_check_compiler_flag(
289296
C
290297
-fsanitize=undefined
291-
HAVE_UNDEFINED_SANITIZER_C
298+
PHP_HAS_UNDEFINED_SANITIZER_C
292299
)
293300
if(CXX IN_LIST enabledLanguages)
294301
php_check_compiler_flag(
295302
CXX
296303
-fsanitize=undefined
297-
HAVE_UNDEFINED_SANITIZER_CXX
304+
PHP_HAS_UNDEFINED_SANITIZER_CXX
298305
)
299306
endif()
300307
cmake_pop_check_state()
301308

302-
if(HAVE_UNDEFINED_SANITIZER_C OR HAVE_UNDEFINED_SANITIZER_CXX)
309+
if(PHP_HAS_UNDEFINED_SANITIZER_C OR PHP_HAS_UNDEFINED_SANITIZER_CXX)
303310
target_compile_options(
304311
php_config
305312
INTERFACE
@@ -320,18 +327,18 @@ if(PHP_UNDEFINED_SANITIZER)
320327
php_check_compiler_flag(
321328
C
322329
-fno-sanitize=object-size
323-
HAVE_OBJECT_SIZE_SANITIZER_C
330+
PHP_HAS_OBJECT_SIZE_SANITIZER_C
324331
)
325332
if(CXX IN_LIST enabledLanguages)
326333
php_check_compiler_flag(
327334
CXX
328335
-fno-sanitize=object-size
329-
HAVE_OBJECT_SIZE_SANITIZER_CXX
336+
PHP_HAS_OBJECT_SIZE_SANITIZER_CXX
330337
)
331338
endif()
332339
cmake_pop_check_state()
333340

334-
if(HAVE_OBJECT_SIZE_SANITIZER_C OR HAVE_OBJECT_SIZE_SANITIZER_CXX)
341+
if(PHP_HAS_OBJECT_SIZE_SANITIZER_C OR PHP_HAS_OBJECT_SIZE_SANITIZER_CXX)
335342
target_compile_options(
336343
php_config
337344
INTERFACE
@@ -348,15 +355,15 @@ if(PHP_UNDEFINED_SANITIZER)
348355
# Clang 17 adds stricter function pointer compatibility checks where pointer
349356
# args cannot be cast to void*. In that case, set -fno-sanitize=function.
350357
if(
351-
NOT DEFINED PHP_HAVE_UBSAN_EXITCODE
358+
NOT DEFINED PHP_HAS_UBSAN_EXITCODE
352359
AND CMAKE_CROSSCOMPILING
353360
AND NOT CMAKE_CROSSCOMPILING_EMULATOR
354361
AND CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang"
355362
AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 17
356363
)
357364
# When cross-compiling without emulator and using Clang 17 and greater,
358365
# assume that -fno-sanitize=function needs to be added.
359-
set(PHP_HAVE_UBSAN_EXITCODE 1)
366+
set(PHP_HAS_UBSAN_EXITCODE 1)
360367
endif()
361368

362369
cmake_push_check_state(RESET)
@@ -372,32 +379,32 @@ if(PHP_UNDEFINED_SANITIZER)
372379
f("foo");
373380
return 0;
374381
}
375-
]] PHP_HAVE_UBSAN)
382+
]] PHP_HAS_UBSAN)
376383
cmake_pop_check_state()
377384

378-
if(NOT PHP_HAVE_UBSAN)
385+
if(NOT PHP_HAS_UBSAN)
379386
php_check_compiler_flag(
380387
C
381388
-fno-sanitize=function
382-
HAVE_FNO_SANITIZE_FUNCTION_C
389+
PHP_HAS_FNO_SANITIZE_FUNCTION_C
383390
)
384391
if(CXX IN_LIST enabledLanguages)
385392
php_check_compiler_flag(
386393
CXX
387394
-fno-sanitize=function
388-
HAVE_FNO_SANITIZE_FUNCTION_CXX
395+
PHP_HAS_FNO_SANITIZE_FUNCTION_CXX
389396
)
390397
endif()
391398

392-
if(HAVE_FNO_SANITIZE_FUNCTION_C)
399+
if(PHP_HAS_FNO_SANITIZE_FUNCTION_C)
393400
target_compile_options(
394401
php_config
395402
INTERFACE
396403
$<$<COMPILE_LANGUAGE:ASM,C>:-fno-sanitize=function>
397404
)
398405
endif()
399406

400-
if(HAVE_FNO_SANITIZE_FUNCTION_CXX)
407+
if(PHP_HAS_FNO_SANITIZE_FUNCTION_CXX)
401408
target_compile_options(
402409
php_config
403410
INTERFACE
@@ -417,25 +424,25 @@ if(PHP_MEMORY_SANITIZER OR PHP_ADDRESS_SANITIZER OR PHP_UNDEFINED_SANITIZER)
417424
php_check_compiler_flag(
418425
C
419426
-fno-omit-frame-pointer
420-
HAVE_FNO_OMIT_FRAME_POINTER_C
427+
PHP_HAS_FNO_OMIT_FRAME_POINTER_C
421428
)
422429
if(CXX IN_LIST enabledLanguages)
423430
php_check_compiler_flag(
424431
CXX
425432
-fno-omit-frame-pointer
426-
HAVE_FNO_OMIT_FRAME_POINTER_CXX
433+
PHP_HAS_FNO_OMIT_FRAME_POINTER_CXX
427434
)
428435
endif()
429436

430-
if(HAVE_FNO_OMIT_FRAME_POINTER_C)
437+
if(PHP_HAS_FNO_OMIT_FRAME_POINTER_C)
431438
target_compile_options(
432439
php_config
433440
INTERFACE
434441
$<$<COMPILE_LANGUAGE:ASM,C>:-fno-omit-frame-pointer>
435442
)
436443
endif()
437444

438-
if(HAVE_FNO_OMIT_FRAME_POINTER_CXX)
445+
if(PHP_HAS_FNO_OMIT_FRAME_POINTER_CXX)
439446
target_compile_options(
440447
php_config
441448
INTERFACE
@@ -457,9 +464,9 @@ if(CMAKE_C_STANDARD EQUAL 99)
457464
php_check_compiler_flag(
458465
C
459466
-Wno-typedef-redefinition
460-
_HAVE_WNO_TYPEDEF_REDEFINITION
467+
PHP_HAS_WNO_TYPEDEF_REDEFINITION
461468
)
462-
if(_HAVE_WNO_TYPEDEF_REDEFINITION)
469+
if(PHP_HAS_WNO_TYPEDEF_REDEFINITION)
463470
target_compile_options(
464471
php_config
465472
INTERFACE

0 commit comments

Comments
 (0)