https://github.com/python/cpython/commit/288cbacfb91377eb591f44c9ae16e7cbf092abd8
commit: 288cbacfb91377eb591f44c9ae16e7cbf092abd8
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: Fidget-Spinner <[email protected]>
date: 2026-04-11T01:32:26+08:00
summary:

[3.14] gh-148284: Block inlining of gigantic functions in ceval.c for clang 22 
(GH-148334) (GH-148349)

gh-148284: Block inlining of gigantic functions in ceval.c for clang 22 
(GH-148334)
(cherry picked from commit e007631e9949ab806742eb61076112e9e2e3e22e)

Co-authored-by: Ken Jin <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-04-10-14-20-54.gh-issue-148284.HKs-S_.rst
M Doc/using/configure.rst
M Makefile.pre.in
M configure
M configure.ac

diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst
index 157432acbc9d21..2c0d81d4800701 100644
--- a/Doc/using/configure.rst
+++ b/Doc/using/configure.rst
@@ -1506,6 +1506,12 @@ Compiler flags
 
    .. versionadded:: 3.7
 
+.. envvar:: CFLAGS_CEVAL
+
+   Flags used to compile ``Python/ceval.c``.
+
+   .. versionadded:: 3.14.5
+
 .. envvar:: CCSHARED
 
    Compiler flags used to build a shared library.
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 80a1b590c2f9b8..797a6d6cceece0 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -126,6 +126,8 @@ PY_CORE_CFLAGS=     $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE
 PY_CORE_LDFLAGS=$(PY_LDFLAGS) $(PY_LDFLAGS_NODIST)
 # Strict or non-strict aliasing flags used to compile dtoa.c, see above
 CFLAGS_ALIASING=@CFLAGS_ALIASING@
+# Compilation flags only for ceval.c.
+CFLAGS_CEVAL=@CFLAGS_CEVAL@
 
 
 # Machine-dependent subdirectories
@@ -3142,6 +3144,9 @@ regen-jit:
 Python/dtoa.o: Python/dtoa.c
        $(CC) -c $(PY_CORE_CFLAGS) $(CFLAGS_ALIASING) -o $@ $<
 
+Python/ceval.o: Python/ceval.c
+       $(CC) -c $(PY_CORE_CFLAGS) $(CFLAGS_CEVAL) -o $@ $<
+
 # Run reindent on the library
 .PHONY: reindent
 reindent:
diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-04-10-14-20-54.gh-issue-148284.HKs-S_.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-10-14-20-54.gh-issue-148284.HKs-S_.rst
new file mode 100644
index 00000000000000..a74f6c1a61affd
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-10-14-20-54.gh-issue-148284.HKs-S_.rst
@@ -0,0 +1 @@
+Fix high stack consumption in Python's interpreter loop on Clang 22 by setting 
function limits for inlining when building with computed gotos.
diff --git a/configure b/configure
index 8cfdda5a29b00d..7621eeabeb85db 100755
--- a/configure
+++ b/configure
@@ -826,6 +826,7 @@ OPENSSL_LDFLAGS
 OPENSSL_LIBS
 OPENSSL_INCLUDES
 ENSUREPIP
+CFLAGS_CEVAL
 SRCDIRS
 THREADHEADERS
 PANEL_LIBS
@@ -30049,6 +30050,52 @@ printf "%s\n" "#define HAVE_GLIBC_MEMMOVE_BUG 1" 
>>confdefs.h
 
 fi
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if we need to manually 
block large inlining in ceval.c" >&5
+printf %s "checking if we need to manually block large inlining in ceval.c... 
" >&6; }
+if test "$cross_compiling" = yes
+then :
+  block_huge_inlining_in_ceval=undefined
+else case e in #(
+  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int main(void) {
+// See gh-148284: Clang 22 seems to have interactions with inlining
+// and the stackref buffer which cause 40 kB of stack usage on x86-64
+// in buggy versions of _PyEval_EvalFrameDefault() in computed goto
+// interpreter. The normal usage seen is normally 1-2 kB.
+#if defined(__clang__) && (__clang_major__ == 22)
+    return 1;
+#else
+    return 0;
+#endif
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"
+then :
+  block_huge_inlining_in_ceval=no
+else case e in #(
+  e) block_huge_inlining_in_ceval=yes ;;
+esac
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
+esac
+fi
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: 
$block_huge_inlining_in_ceval" >&5
+printf "%s\n" "$block_huge_inlining_in_ceval" >&6; }
+
+if test "$block_huge_inlining_in_ceval" = yes && test "$ac_cv_computed_gotos" 
= yes; then
+    # gh-148284: Suppress inlining of functions whose stack size exceeds
+    # 512 bytes. This number should be tuned to follow the C stack
+    # consumption in _PyEval_EvalFrameDefault() on computed goto
+    # interpreter.
+    CFLAGS_CEVAL="$CFLAGS_CEVAL -finline-max-stacksize=512"
+fi
+
+
 if test "$ac_cv_gcc_asm_for_x87" = yes; then
     # Some versions of gcc miscompile inline asm:
     # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
diff --git a/configure.ac b/configure.ac
index 1acb91fd27b9d2..21df2245402eea 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7244,6 +7244,34 @@ if test "$have_glibc_memmove_bug" = yes; then
      for memmove and bcopy.])
 fi
 
+AC_MSG_CHECKING([if we need to manually block large inlining in ceval.c])
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+int main(void) {
+// See gh-148284: Clang 22 seems to have interactions with inlining
+// and the stackref buffer which cause 40 kB of stack usage on x86-64
+// in buggy versions of _PyEval_EvalFrameDefault() in computed goto
+// interpreter. The normal usage seen is normally 1-2 kB.
+#if defined(__clang__) && (__clang_major__ == 22)
+    return 1;
+#else
+    return 0;
+#endif
+}
+]])],
+[block_huge_inlining_in_ceval=no],
+[block_huge_inlining_in_ceval=yes],
+[block_huge_inlining_in_ceval=undefined])
+AC_MSG_RESULT([$block_huge_inlining_in_ceval])
+
+if test "$block_huge_inlining_in_ceval" = yes && test "$ac_cv_computed_gotos" 
= yes; then
+    # gh-148284: Suppress inlining of functions whose stack size exceeds
+    # 512 bytes. This number should be tuned to follow the C stack
+    # consumption in _PyEval_EvalFrameDefault() on computed goto
+    # interpreter.
+    CFLAGS_CEVAL="$CFLAGS_CEVAL -finline-max-stacksize=512"
+fi
+AC_SUBST([CFLAGS_CEVAL])
+
 if test "$ac_cv_gcc_asm_for_x87" = yes; then
     # Some versions of gcc miscompile inline asm:
     # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491

_______________________________________________
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