Skip to content

[3.13] gh-120367: fix bug where compiler detects redundant jump after pseudo op replacement (GH-120714) #120716

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
Jun 18, 2024
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
27 changes: 26 additions & 1 deletion Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,32 @@ def test_compile_redundant_jumps_and_nops_after_moving_cold_blocks(self):

tree = ast.parse(code)

# make all instructions locations the same to create redundancies
# make all instruction locations the same to create redundancies
for node in ast.walk(tree):
if hasattr(node,"lineno"):
del node.lineno
del node.end_lineno
del node.col_offset
del node.end_col_offset

compile(ast.fix_missing_locations(tree), "<file>", "exec")

def test_compile_redundant_jump_after_convert_pseudo_ops(self):
# See gh-120367
code=textwrap.dedent("""
if name_2:
pass
else:
try:
pass
except:
pass
~name_5
""")

tree = ast.parse(code)

# make all instruction locations the same to create redundancies
for node in ast.walk(tree):
if hasattr(node,"lineno"):
del node.lineno
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where compiler creates a redundant jump during pseudo-op replacement. Can only happen with a synthetic AST that has a try on the same line as the instruction following the exception handler.
2 changes: 1 addition & 1 deletion Python/flowgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -2361,7 +2361,7 @@ convert_pseudo_ops(cfg_builder *g)
}
}
}
return remove_redundant_nops(g);
return remove_redundant_nops_and_jumps(g);
}

static inline bool
Expand Down
Loading