8000 [3.12] gh-107901: Fix missing line number on BACKWARD_JUMP at the end of a for loop (GH-108242) by miss-islington · Pull Request #108275 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.12] gh-107901: Fix missing line number on BACKWARD_JUMP at the end of a for loop (GH-108242) #108275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2023
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
gh-107901: Fix missing line number on BACKWARD_JUMP at the end of a f…
…or loop (GH-108242)

(cherry picked from commit a1cc74c)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
  • Loading branch information
iritkatriel authored and miss-islington committed Aug 22, 2023
commit 0580a15c4aaede273b37ecc299042f72e3f39d9a
14 changes: 14 additions & 0 deletions Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,20 @@ async def test(aseq):
code_lines = self.get_code_lines(test.__code__)
self.assertEqual(expected_lines, code_lines)

def test_lineno_of_backward_jump(self):
# Issue gh-107901
def f():
for i in x:
if y:
pass

linenos = list(inst.positions.lineno
for inst in dis.get_instructions(f.__code__)
if inst.opname == 'JUMP_BACKWARD')

self.assertTrue(len(linenos) > 0)
self.assertTrue(all(l is not None for l in linenos))

def test_big_dict_literal(self):
# The compiler has a flushing point in "compiler_dict" that calls compiles
# a portion of the dictionary literal when the loop that iterates over the items
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix missing line number on :opcode:`JUMP_BACKWARD` at the end of a for loop.
2 changes: 1 addition & 1 deletion Python/flowgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ normalize_jumps_in_block(cfg_builder *g, basicblock *b) {
if (backwards_jump == NULL) {
return ERROR;
}
basicblock_addop(backwards_jump, JUMP, target->b_label.id, NO_LOCATION);
basicblock_addop(backwards_jump, JUMP, target->b_label.id, last->i_loc);
backwards_jump->b_instr[0].i_target = target;
last->i_opcode = reversed_opcode;
last->i_target = b->b_next;
Expand Down
0