gcc/configure: Properly remove -O flags from C[XX]FLAGS

Message ID mvma5dblpyp.fsf@suse.de
State New
Headers
Series gcc/configure: Properly remove -O flags from C[XX]FLAGS |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply

Commit Message

Andreas Schwab Dec. 4, 2024, 10:09 a.m. UTC
  PR bootstrap/117893
	* configure.ac: Use shell loop to remove -O flags.
	* configure: Regenerate.
  

Comments

Richard Biener Dec. 4, 2024, 10:41 a.m. UTC | #1
On Wed, Dec 4, 2024 at 11:10 AM Andreas Schwab <schwab@suse.de> wrote:
>
>         PR bootstrap/117893
>         * configure.ac: Use shell loop to remove -O flags.
>         * configure: Regenerate.

OK.

Richard.

> diff --git a/gcc/configure.ac b/gcc/configure.ac
> index e9bddc6db21..ed8d9596668 100644
> --- a/gcc/configure.ac
> +++ b/gcc/configure.ac
> @@ -463,12 +463,28 @@ ACX_PROG_GDC([-I"$srcdir"/d])
>  # Do configure tests with the C++ compiler, since that's what we build with.
>  AC_LANG(C++)
>
> -# Remove the -O2: for historical reasons, unless bootstrapping we prefer
> +# Remove all -O flags: for historical reasons, unless bootstrapping we prefer
>  # optimizations to be activated explicitly by the toplevel.
>  case "$CC" in
>    */prev-gcc/xgcc*) ;;
> -  *) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[[      ]]//" -e "s/-O[[gs]][[  ]]//" -e "s/[[^,]]-O[[0-9]]*[[  ]]//" `
> -     CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[[  ]]//" -e "s/-O[[gs]][[  ]]//" -e "s/[[^,]]-O[[0-9]]*[[  ]]//" ` ;;
> +  *)
> +    new_CFLAGS=
> +    for flag in $CFLAGS; do
> +      case $flag in
> +       -O*) ;;
> +       *) new_CFLAGS="$new_CFLAGS $flag" ;;
> +      esac
> +    done
> +    CFLAGS=$new_CFLAGS
> +    new_CXXFLAGS=
> +    for flag in $CXXFLAGS; do
> +      case $flag in
> +       -O*) ;;
> +       *) new_CXXFLAGS="$new_CXXFLAGS $flag" ;;
> +      esac
> +    done
> +    CXXFLAGS=$new_CXXFLAGS
> +    ;;
>  esac
>  AC_SUBST(CFLAGS)
>  AC_SUBST(CXXFLAGS)
> --
> 2.47.1
>
>
> --
> Andreas Schwab, SUSE Labs, schwab@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."
  

Patch

diff --git a/gcc/configure.ac b/gcc/configure.ac
index e9bddc6db21..ed8d9596668 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -463,12 +463,28 @@  ACX_PROG_GDC([-I"$srcdir"/d])
 # Do configure tests with the C++ compiler, since that's what we build with.
 AC_LANG(C++)
 
-# Remove the -O2: for historical reasons, unless bootstrapping we prefer
+# Remove all -O flags: for historical reasons, unless bootstrapping we prefer
 # optimizations to be activated explicitly by the toplevel.
 case "$CC" in
   */prev-gcc/xgcc*) ;;
-  *) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[[ 	]]//" -e "s/-O[[gs]][[ 	]]//" -e "s/[[^,]]-O[[0-9]]*[[ 	]]//" `
-     CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[[ 	]]//" -e "s/-O[[gs]][[ 	]]//" -e "s/[[^,]]-O[[0-9]]*[[ 	]]//" ` ;;
+  *)
+    new_CFLAGS=
+    for flag in $CFLAGS; do
+      case $flag in
+	-O*) ;;
+	*) new_CFLAGS="$new_CFLAGS $flag" ;;
+      esac
+    done
+    CFLAGS=$new_CFLAGS
+    new_CXXFLAGS=
+    for flag in $CXXFLAGS; do
+      case $flag in
+	-O*) ;;
+	*) new_CXXFLAGS="$new_CXXFLAGS $flag" ;;
+      esac
+    done
+    CXXFLAGS=$new_CXXFLAGS
+    ;;
 esac
 AC_SUBST(CFLAGS)
 AC_SUBST(CXXFLAGS)