From 05e2a91228a27ecda54be7ab3e56926b3929fbe1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 1 Feb 2022 13:40:18 +0100 Subject: [PATCH 1/2] bpo-46600: ./configure --with-pydebug uses -Og with clang Fix the test checking if the C compiler supports -Og option in the ./configure script to also use -Og on clang which supports it. --- .../2022-02-01-14-07-37.bpo-46600.NNLnfj.rst | 3 ++ configure | 52 ++++++++++++++++--- configure.ac | 30 ++++++++--- 3 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2022-02-01-14-07-37.bpo-46600.NNLnfj.rst diff --git a/Misc/NEWS.d/next/Build/2022-02-01-14-07-37.bpo-46600.NNLnfj.rst b/Misc/NEWS.d/next/Build/2022-02-01-14-07-37.bpo-46600.NNLnfj.rst new file mode 100644 index 00000000000000..1fab655f9b271b --- /dev/null +++ b/Misc/NEWS.d/next/Build/2022-02-01-14-07-37.bpo-46600.NNLnfj.rst @@ -0,0 +1,3 @@ +Fix the test checking if the C compiler supports ``-Og`` option in the +``./configure`` script to also use ``-Og`` on clang which supports it. Patch +by Victor Stinner. diff --git a/configure b/configure index da4af32cc17aaf..e93ee7d357848e 100755 --- a/configure +++ b/configure @@ -7623,6 +7623,50 @@ case $CC in fi esac +# Check if CC supports -Og optimization level +save_CFLAGS="$CFLAGS" +CFLAGS="-Og" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Og optimization level" >&5 +$as_echo_n "checking if $CC supports -Og optimization level... " >&6; } +if ${ac_cv_cc_supports_og+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + +int +main () +{ + + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + ac_cv_cc_supports_og=yes + +else + + ac_cv_cc_supports_og=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cc_supports_og" >&5 +$as_echo "$ac_cv_cc_supports_og" >&6; } +CFLAGS="$save_CFLAGS" + +# Optimization messes up debuggers, so turn it off for +# debug builds. +PYDEBUG_CFLAGS="-O0" +if test "x$ac_cv_cc_supports_og" = xyes; then : + PYDEBUG_CFLAGS="-Og" +fi + # tweak OPT based on compiler and platform, only if the user didn't set # it on the command line @@ -7648,13 +7692,7 @@ then case $ac_cv_prog_cc_g in yes) if test "$Py_DEBUG" = 'true' ; then - # Optimization messes up debuggers, so turn it off for - # debug builds. - if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then - OPT="-g -Og -Wall" - else - OPT="-g -O0 -Wall" - fi + OPT="-g $PYDEBUG_CFLAGS -Wall" else OPT="-g $WRAP -O3 -Wall" fi diff --git a/configure.ac b/configure.ac index 5a076646b96dd7..97dc1f0937c858 100644 --- a/configure.ac +++ b/configure.ac @@ -1791,6 +1791,28 @@ case $CC in fi esac +# Check if CC supports -Og optimization level +save_CFLAGS="$CFLAGS" +CFLAGS="-Og" +AC_CACHE_CHECK([if $CC supports -Og optimization level], + [ac_cv_cc_supports_og], + AC_COMPILE_IFELSE( + [ + AC_LANG_PROGRAM([[]], [[]]) + ],[ + ac_cv_cc_supports_og=yes + ],[ + ac_cv_cc_supports_og=no + ]) +) +CFLAGS="$save_CFLAGS" + +# Optimization messes up debuggers, so turn it off for +# debug builds. +PYDEBUG_CFLAGS="-O0" +AS_VAR_IF([ac_cv_cc_supports_og], [yes], + [PYDEBUG_CFLAGS="-Og"]) + # tweak OPT based on compiler and platform, only if the user didn't set # it on the command line AC_SUBST(OPT) @@ -1816,13 +1838,7 @@ then case $ac_cv_prog_cc_g in yes) if test "$Py_DEBUG" = 'true' ; then - # Optimization messes up debuggers, so turn it off for - # debug builds. - if "$CC" -v --help 2>/dev/null |grep -- -Og > /dev/null; then - OPT="-g -Og -Wall" - else - OPT="-g -O0 -Wall" - fi + OPT="-g $PYDEBUG_CFLAGS -Wall" else OPT="-g $WRAP -O3 -Wall" fi From e11c116a6de56326c9e21c38bfde70fc721b3b40 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 1 Feb 2022 14:23:17 +0100 Subject: [PATCH 2/2] Use _SAVE_VAR/_RESTORE_VAR --- configure | 4 ++-- configure.ac | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure b/configure index e93ee7d357848e..015b51645f5be7 100755 --- a/configure +++ b/configure @@ -7624,7 +7624,7 @@ case $CC in esac # Check if CC supports -Og optimization level -save_CFLAGS="$CFLAGS" +save_CFLAGS=$CFLAGS CFLAGS="-Og" { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Og optimization level" >&5 $as_echo_n "checking if $CC supports -Og optimization level... " >&6; } @@ -7658,7 +7658,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cc_supports_og" >&5 $as_echo "$ac_cv_cc_supports_og" >&6; } -CFLAGS="$save_CFLAGS" +CFLAGS=$save_CFLAGS # Optimization messes up debuggers, so turn it off for # debug builds. diff --git a/configure.ac b/configure.ac index 97dc1f0937c858..6204747edfc25a 100644 --- a/configure.ac +++ b/configure.ac @@ -1792,7 +1792,7 @@ case $CC in esac # Check if CC supports -Og optimization level -save_CFLAGS="$CFLAGS" +_SAVE_VAR([CFLAGS]) CFLAGS="-Og" AC_CACHE_CHECK([if $CC supports -Og optimization level], [ac_cv_cc_supports_og], @@ -1805,7 +1805,7 @@ AC_CACHE_CHECK([if $CC supports -Og optimization level], ac_cv_cc_supports_og=no ]) ) -CFLAGS="$save_CFLAGS" +_RESTORE_VAR([CFLAGS]) # Optimization messes up debuggers, so turn it off for # debug builds.