From 6936a38478b4ef576352b27d0674bb4ecd0cb9e9 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Thu, 16 Oct 2025 21:59:01 +0100 Subject: [PATCH] Just punt on large opargs for now --- Python/bytecodes.c | 6 ++++-- Python/executor_cases.c.h | 5 +++-- Python/optimizer.c | 8 +++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 812b323c137b..5ab80565d6d4 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -5407,9 +5407,11 @@ dummy_func( } tier2 op(_ERROR_POP_N, (target/2 --)) { - assert(target != 0); assert(oparg == 0); - frame->instr_ptr = _PyFrame_GetBytecode(frame) + target; + _Py_CODEUNIT *current_instr = _PyFrame_GetBytecode(frame) + target; + _Py_CODEUNIT *next_instr = current_instr + 1 + _PyOpcode_Caches[_PyOpcode_Deopt[current_instr->op.code]]; + // gh-140104: The exception handler expects frame->instr_ptr to be pointing to next_instr, not this_instr! + frame->instr_ptr = next_instr; SYNC_SP(); GOTO_TIER_ONE(NULL, 0); } diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 58c57ea6b96f..f13baadd3bc7 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -7459,9 +7459,10 @@ case _ERROR_POP_N: { oparg = CURRENT_OPARG(); uint32_t target = (uint32_t)CURRENT_OPERAND0(); - assert(target != 0); assert(oparg == 0); - frame->instr_ptr = _PyFrame_GetBytecode(frame) + target; + _Py_CODEUNIT *current_instr = _PyFrame_GetBytecode(frame) + target; + _Py_CODEUNIT *next_instr = current_instr + 1 + _PyOpcode_Caches[_PyOpcode_Deopt[current_instr->op.code]]; + frame->instr_ptr = next_instr; GOTO_TIER_ONE(NULL, 0); break; } diff --git a/Python/optimizer.c b/Python/optimizer.c index a8df28cd2a86..e4b29124d17a 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -585,11 +585,10 @@ _PyJIT_translate_single_bytecode_to_trace( DPRINTF(2, "%d: %s(%d)\n", target, _PyOpcode_OpName[opcode], oparg); - if ((uint16_t)oparg != (uint64_t)oparg) { + // TODO support EXTENDED_ARG + if (oparg > 255) { goto unsupported; } - // One for possible _DEOPT, one because _CHECK_VALIDITY itself might _DEOPT - max_length -= 2; if (opcode == EXTENDED_ARG) { return 1; @@ -606,6 +605,9 @@ _PyJIT_translate_single_bytecode_to_trace( return 1; } + // One for possible _DEOPT, one because _CHECK_VALIDITY itself might _DEOPT + max_length -= 2; + if (opcode == ENTER_EXECUTOR) { ADD_TO_TRACE(_CHECK_VALIDITY, 0, 0, target); ADD_TO_TRACE(_SET_IP, 0, (uintptr_t)target_instr, target); -- 2.47.3