Skip to content

Commit c639614

Browse files
arnaud-lbpetk
andcommitted
Do not remove -O0 in the middle of a flag
Fixes GH-15826 Closes GH-15828 Co-authored-by: Peter Kokot <[email protected]>
1 parent 60c2687 commit c639614

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

build/php.m4

+12
Original file line numberDiff line numberDiff line change
@@ -2735,3 +2735,15 @@ AC_DEFUN([PHP_PATCH_CONFIG_HEADERS], [
27352735
$SED -e 's/^#undef PACKAGE_[^ ]*/\/\* & \*\//g' < $srcdir/$1 \
27362736
> $srcdir/$1.tmp && mv $srcdir/$1.tmp $srcdir/$1
27372737
])
2738+
2739+
dnl
2740+
dnl PHP_REMOVE_OPTIMIZATION_FLAGS
2741+
dnl
2742+
dnl Removes known compiler optimization flags like -O, -O0, -O1, ..., -Ofast
2743+
dnl from CFLAGS and CXXFLAGS.
2744+
dnl
2745+
AC_DEFUN([PHP_REMOVE_OPTIMIZATION_FLAGS], [
2746+
sed_script='s/\([[\t ]]\|^\)-O\([[0-9gsz]]\|fast\|\)\([[\t ]]\|$\)/\1/g'
2747+
CFLAGS=$(echo "$CFLAGS" | $SED -e "$sed_script")
2748+
CXXFLAGS=$(echo "$CXXFLAGS" | $SED -e "$sed_script")
2749+
])

configure.ac

+2-10
Original file line numberDiff line numberDiff line change
@@ -845,11 +845,7 @@ if test "$PHP_GCOV" = "yes"; then
845845
PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/build/Makefile.gcov, $abs_srcdir)
846846

847847
dnl Remove all optimization flags from CFLAGS.
848-
changequote({,})
849-
dnl Discard known '-O...' flags, including just '-O', but do not remove only '-O' in '-Ounknown'
850-
CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)//g'`
851-
CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)//g'`
852-
changequote([,])
848+
PHP_REMOVE_OPTIMIZATION_FLAGS
853849

854850
dnl Add the special gcc flags.
855851
CFLAGS="$CFLAGS -O0 -fprofile-arcs -ftest-coverage"
@@ -866,11 +862,7 @@ PHP_ARG_ENABLE([debug],
866862
if test "$PHP_DEBUG" = "yes"; then
867863
PHP_DEBUG=1
868864
ZEND_DEBUG=yes
869-
changequote({,})
870-
dnl Discard known '-O...' flags, including just '-O', but do not remove only '-O' in '-Ounknown'
871-
CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)//g'`
872-
CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)//g'`
873-
changequote([,])
865+
PHP_REMOVE_OPTIMIZATION_FLAGS
874866
dnl Add -O0 only if GCC or ICC is used.
875867
if test "$GCC" = "yes" || test "$ICC" = "yes"; then
876868
CFLAGS="$CFLAGS -O0"

scripts/phpize.m4

+1-5
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ dnl Discard optimization flags when debugging is enabled.
115115
if test "$PHP_DEBUG" = "yes"; then
116116
PHP_DEBUG=1
117117
ZEND_DEBUG=yes
118-
changequote({,})
119-
dnl Discard known '-O...' flags, including just '-O', but do not remove only '-O' in '-Ounknown'
120-
CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)//g'`
121-
CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)//g'`
122-
changequote([,])
118+
PHP_REMOVE_OPTIMIZATION_FLAGS
123119
dnl Add -O0 only if GCC or ICC is used.
124120
if test "$GCC" = "yes" || test "$ICC" = "yes"; then
125121
CFLAGS="$CFLAGS -O0"

0 commit comments

Comments
 (0)