]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Just punt on large opargs for now
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Thu, 16 Oct 2025 20:59:01 +0000 (21:59 +0100)
committerKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Thu, 16 Oct 2025 20:59:01 +0000 (21:59 +0100)
Python/bytecodes.c
Python/executor_cases.c.h
Python/optimizer.c

index 812b323c137b2b0faf881e972e7492bc95f9e1d0..5ab80565d6d486cfdb601d46bfc00bc6d7654233 100644 (file)
@@ -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);
         }
index 58c57ea6b96fa84c7e182fe147cdb1db0f36caaa..f13baadd3bc76f54699a71cb824f37dd184adfb5 100644 (file)
         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;
         }
index a8df28cd2a86f47684a37e495864638be652c0bc..e4b29124d17a140751e6e3d58240e38652ae2204 100644 (file)
@@ -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);