From ffb62d926b55f6758b9edb19296bcf9614ca2019 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Thu, 14 Aug 2025 22:10:20 +0800 Subject: [PATCH 1/5] Fix a bug in the JIT with many local variables --- Python/optimizer_analysis.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c index dd3e49b83d9971..81a5efbebd1748 100644 --- a/Python/optimizer_analysis.c +++ b/Python/optimizer_analysis.c @@ -482,15 +482,19 @@ optimize_uops( _PyUOpInstruction *corresponding_check_stack = NULL; _Py_uop_abstractcontext_init(ctx); + + // 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; + _Py_UOpsAbstractFrame *frame = _Py_uop_frame_new(ctx, co, curr_stacklen, NULL, 0); if (frame == NULL) { return -1; } 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++) { From d33a8d92d93662b442443c6ff2d2d7a8dd75e27b Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 14 Aug 2025 14:18:37 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2025-08-14-14-18-29.gh-issue-137728.HdYS9R.rst | 1 + 1 file changed, 1 insertion(+) 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 00000000000000..0ff8cf4f64e5b2 --- /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 a bug in the JIT with many local variables causing a segfault. From 90e89dfeded980a223c2a2ba062ac795da24a250 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Thu, 14 Aug 2025 22:30:22 +0800 Subject: [PATCH 3/5] Fix the other thing too --- .../2025-08-14-14-18-29.gh-issue-137728.HdYS9R.rst | 2 +- Python/optimizer_analysis.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 index 0ff8cf4f64e5b2..dab07b143fe3d1 100644 --- 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 @@ -1 +1 @@ -Fix a bug in the JIT with many local variables causing a segfault. +Fix the JIT handling of many local variables. This previously caused a segfault. diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c index 81a5efbebd1748..f157b5dc17b716 100644 --- a/Python/optimizer_analysis.c +++ b/Python/optimizer_analysis.c @@ -491,7 +491,7 @@ optimize_uops( _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; From ad5926ea252c05a98de593e30cfd754f86e264a3 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Thu, 14 Aug 2025 22:32:29 +0800 Subject: [PATCH 4/5] Update 2025-08-14-14-18-29.gh-issue-137728.HdYS9R.rst --- .../2025-08-14-14-18-29.gh-issue-137728.HdYS9R.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index dab07b143fe3d1..cc4a55ddf383ec 100644 --- 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 @@ -1 +1 @@ -Fix the JIT handling of many local variables. This previously caused a segfault. +Fix the JIT's handling of many local variables. This previously caused a segfault. From 16bd3145c9d2ad04b82d81493d3445728143db48 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Wed, 20 Aug 2025 16:20:35 +0800 Subject: [PATCH 5/5] Address review --- Python/optimizer_analysis.c | 7 ------- Python/optimizer_symbols.c | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c index f157b5dc17b716..533d70580e4cc0 100644 --- a/Python/optimizer_analysis.c +++ b/Python/optimizer_analysis.c @@ -482,13 +482,6 @@ optimize_uops( _PyUOpInstruction *corresponding_check_stack = NULL; _Py_uop_abstractcontext_init(ctx); - - // 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; - _Py_UOpsAbstractFrame *frame = _Py_uop_frame_new(ctx, co, curr_stacklen, NULL, 0); if (frame == NULL) { return 0; diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index 8a3df236c80626..8169ce9df5aae6 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