From 7fda8b66debb24e0520b94c3769b648c7305f84e Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Wed, 20 Aug 2025 22:53:54 +0800 Subject: [PATCH] gh-137728 gh-137762: Fix bugs in the JIT with many local variables (GH-137764) --- .../2025-08-14-14-18-29.gh-issue-137728.HdYS9R.rst | 1 + Python/optimizer_analysis.c | 5 +---- Python/optimizer_symbols.c | 7 +++++++ 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-08-14-14-18-29.gh-issue-137728.HdYS9R.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-08-14-14-18-29.gh-issue-137728.HdYS9R.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-08-14-14-18-29.gh-issue-137728.HdYS9R.rst new file mode 100644 index 000000000000..cc4a55ddf383 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-08-14-14-18-29.gh-issue-137728.HdYS9R.rst @@ -0,0 +1 @@ +Fix the JIT's handling of many local variables. This previously caused a segfault. diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c index dd3e49b83d99..533d70580e4c 100644 --- a/Python/optimizer_analysis.c +++ b/Python/optimizer_analysis.c @@ -484,13 +484,10 @@ optimize_uops( _Py_uop_abstractcontext_init(ctx); _Py_UOpsAbstractFrame *frame = _Py_uop_frame_new(ctx, co, curr_stacklen, NULL, 0); if (frame == NULL) { - return -1; + return 0; } ctx->curr_frame_depth++; ctx->frame = frame; - ctx->done = false; - ctx->out_of_space = false; - ctx->contradiction = false; _PyUOpInstruction *this_instr = NULL; for (int i = 0; !ctx->done; i++) { diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index 8a3df236c806..8169ce9df5aa 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -888,6 +888,13 @@ _Py_uop_abstractcontext_init(JitOptContext *ctx) // Frame setup ctx->curr_frame_depth = 0; + + // Ctx signals. + // Note: this must happen before frame_new, as it might override + // the result should frame_new set things to bottom. + ctx->done = false; + ctx->out_of_space = false; + ctx->contradiction = false; } int -- 2.47.3