https://github.com/python/cpython/commit/ffaec6e2a11fb7b41facfec7d99e41b29d9d7967
commit: ffaec6e2a11fb7b41facfec7d99e41b29d9d7967
branch: main
author: Taegyun Kim <[email protected]>
committer: AA-Turner <[email protected]>
date: 2025-08-27T01:00:43+02:00
summary:

gh-128042: Emit a ``configure`` warning when ``-O0`` and 
``--enable-optimizations`` are combined (#137975)

Co-authored-by: Adam Turner <[email protected]>

files:
A Misc/NEWS.d/next/Build/2025-08-26-21-18-32.gh-issue-128042.5voC8H.rst
M configure
M configure.ac

diff --git 
a/Misc/NEWS.d/next/Build/2025-08-26-21-18-32.gh-issue-128042.5voC8H.rst 
b/Misc/NEWS.d/next/Build/2025-08-26-21-18-32.gh-issue-128042.5voC8H.rst
new file mode 100644
index 00000000000000..fd85e0fee2162b
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2025-08-26-21-18-32.gh-issue-128042.5voC8H.rst
@@ -0,0 +1 @@
+``./configure`` now warns when ``--enable-optimizations`` and ``CFLAGS=-O0`` 
are both set, suggesting removing ``-O0`` from ``CFLAGS`` for optimal 
performance.  Patch by Taegyun Kim.
diff --git a/configure b/configure
index 568db406dbc67b..bdeab8a6d126a3 100755
--- a/configure
+++ b/configure
@@ -8407,6 +8407,13 @@ fi
 
 
 if test "$Py_OPT" = 'true' ; then
+  # Check for conflicting CFLAGS=-O0 and --enable-optimizations
+  case "$CFLAGS" in
+    *-O0*)
+      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: CFLAGS contains 
-O0 which may conflict with --enable-optimizations. Consider removing -O0 from 
CFLAGS for optimal performance." >&5
+printf "%s\n" "$as_me: WARNING: CFLAGS contains -O0 which may conflict with 
--enable-optimizations. Consider removing -O0 from CFLAGS for optimal 
performance." >&2;}
+      ;;
+  esac
   # Intentionally not forcing Py_LTO='true' here.  Too many toolchains do not
   # compile working code using it and both test_distutils and test_gdb are
   # broken when you do manage to get a toolchain that works with it.  People
diff --git a/configure.ac b/configure.ac
index bbaff7f80352b8..991fa40746be78 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1823,6 +1823,14 @@ fi],
 [AC_MSG_RESULT([no])])
 
 if test "$Py_OPT" = 'true' ; then
+  # Check for conflicting CFLAGS=-O0 and --enable-optimizations
+  case "$CFLAGS" in
+    *-O0*)
+      AC_MSG_WARN([m4_normalize([
+        CFLAGS contains -O0 which may conflict with --enable-optimizations.
+        Consider removing -O0 from CFLAGS for optimal performance.])])
+      ;;
+  esac
   # Intentionally not forcing Py_LTO='true' here.  Too many toolchains do not
   # compile working code using it and both test_distutils and test_gdb are
   # broken when you do manage to get a toolchain that works with it.  People

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to