Skip to content

Commit c23fef4

Browse files
committed
Fix edge case for LOAD_FAST_LOAD_FAST
1 parent d811b0f commit c23fef4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Python/optimizer.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ translate_bytecode_to_trace(
389389
trace_length++;
390390

391391
int trace_length = 0;
392-
while (trace_length + 2 < max_length) {
392+
// ALways reserve space for one uop, plus SET_UP, plus EXIT_TRACE
393+
while (trace_length + 3 <= max_length) {
393394
int opcode = instr->op.code;
394395
int oparg = instr->op.arg;
395396
switch (opcode) {
@@ -402,6 +403,10 @@ translate_bytecode_to_trace(
402403
}
403404
case LOAD_FAST_LOAD_FAST:
404405
{
406+
// Reserve space for two uops (+ SETUP + EXIT_TRACE)
407+
if (trace_length + 4 > max_length) {
408+
goto done;
409+
}
405410
int oparg1 = oparg >> 4;
406411
int oparg2 = oparg & 15;
407412
ADD_TO_TRACE(LOAD_FAST, oparg1);

0 commit comments

Comments
 (0)