Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,16 @@ def if_else_break():
elif instr.opname in HANDLED_JUMPS:
self.assertNotEqual(instr.arg, (line + 1)*INSTR_SIZE)

def test_no_wraparound_jump(self):
# See https://bugs.python.org/issue46724

def while_not_chained(a, b, c):
while not (a < b < c):
pass

for instr in dis.Bytecode(while_not_chained):
self.assertNotEqual(instr.opname, "EXTENDED_ARG")

@requires_debug_ranges()
class TestSourcePositions(unittest.TestCase):
# Ensure that compiled code snippets have correct line and column numbers
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Make sure that all backwards jumps use the ``JUMP_ABSOLUTE`` instruction, rather
than ``JUMP_FORWARD`` with an argument of ``(2**32)+offset``.
5 changes: 5 additions & 0 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -7530,6 +7530,11 @@ normalize_jumps(struct assembler *a)
last->i_opcode = JUMP_FORWARD;
}
}
if (last->i_opcode == JUMP_FORWARD) {
if (last->i_target->b_visited == 1) {
last->i_opcode = JUMP_ABSOLUTE;
}
}
}
}

Expand Down