Do not remove -O0 in the middle of a flag

Fixes GH-15826
Closes GH-15828

Co-authored-by: Peter Kokot <petk@php.net>
This commit is contained in:
Arnaud Le Blanc 2024-09-10 18:40:49 +02:00
parent 60c2687712
commit c639614346
No known key found for this signature in database
GPG Key ID: 0098C05DD15ABC13
3 changed files with 15 additions and 15 deletions

View File

@ -2735,3 +2735,15 @@ AC_DEFUN([PHP_PATCH_CONFIG_HEADERS], [
$SED -e 's/^#undef PACKAGE_[^ ]*/\/\* & \*\//g' < $srcdir/$1 \
> $srcdir/$1.tmp && mv $srcdir/$1.tmp $srcdir/$1
])
dnl
dnl PHP_REMOVE_OPTIMIZATION_FLAGS
dnl
dnl Removes known compiler optimization flags like -O, -O0, -O1, ..., -Ofast
dnl from CFLAGS and CXXFLAGS.
dnl
AC_DEFUN([PHP_REMOVE_OPTIMIZATION_FLAGS], [
sed_script='s/\([[\t ]]\|^\)-O\([[0-9gsz]]\|fast\|\)\([[\t ]]\|$\)/\1/g'
CFLAGS=$(echo "$CFLAGS" | $SED -e "$sed_script")
CXXFLAGS=$(echo "$CXXFLAGS" | $SED -e "$sed_script")
])

View File

@ -845,11 +845,7 @@ if test "$PHP_GCOV" = "yes"; then
PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/build/Makefile.gcov, $abs_srcdir)
dnl Remove all optimization flags from CFLAGS.
changequote({,})
dnl Discard known '-O...' flags, including just '-O', but do not remove only '-O' in '-Ounknown'
CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)//g'`
CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)//g'`
changequote([,])
PHP_REMOVE_OPTIMIZATION_FLAGS
dnl Add the special gcc flags.
CFLAGS="$CFLAGS -O0 -fprofile-arcs -ftest-coverage"
@ -866,11 +862,7 @@ PHP_ARG_ENABLE([debug],
if test "$PHP_DEBUG" = "yes"; then
PHP_DEBUG=1
ZEND_DEBUG=yes
changequote({,})
dnl Discard known '-O...' flags, including just '-O', but do not remove only '-O' in '-Ounknown'
CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)//g'`
CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)//g'`
changequote([,])
PHP_REMOVE_OPTIMIZATION_FLAGS
dnl Add -O0 only if GCC or ICC is used.
if test "$GCC" = "yes" || test "$ICC" = "yes"; then
CFLAGS="$CFLAGS -O0"

View File

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