Skip to content

Commit 1403230

Browse files
committed
Fix the broken GCC strlen optimization check
The -O2 flag needs to be used to detect this check in case other optimization flags are used. This appends the -fno-optimize-strlen even if other optimization flags are used as it is safer then and GCC 8.0 to 8.2 versions are becoming more and more rare.
1 parent 4971e03 commit 1403230

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

cmake/cmake/modules/PHP/CheckBrokenGccStrlenOpt.cmake

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#[=============================================================================[
2-
GCC 8.2 shipped with a strlen() optimization bug, so it didn't properly handle
3-
the 'char val[1]' struct hack. Fixed in GCC 8.3. See https://bugs.php.net/76510
4-
and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86914. If below check is
5-
successful the -fno-optimize-strlen compiler flag should be used.
2+
Early GCC 8 versions shipped with a strlen() optimization bug, so it didn't
3+
properly handle the 'char val[1]' struct hack. Fixed in GCC 8.3. If below check
4+
is successful the -fno-optimize-strlen compiler flag should be added.
5+
See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86914
66
77
Cache variables:
88
@@ -29,6 +29,8 @@ message(CHECK_START "Checking if GCC has broken strlen() optimization")
2929

3030
cmake_push_check_state(RESET)
3131
set(CMAKE_REQUIRED_QUIET TRUE)
32+
# To reproduce the bug, the -O2 flag needs to be used, for example.
33+
set(CMAKE_REQUIRED_FLAGS -O2)
3234

3335
check_source_runs(C [[
3436
#include <stdlib.h>

0 commit comments

Comments
 (0)