mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
[3.13] gh-120367: fix bug where compiler detects redundant jump after pseudo op replacement (GH-120714) (#120716)
This commit is contained in:
parent
07145ddf19
commit
50fa775e68
3 changed files with 28 additions and 2 deletions
|
@ -519,7 +519,32 @@ class TestSpecifics(unittest.TestCase):
|
||||||
|
|
||||||
tree = ast.parse(code)
|
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):
|
for node in ast.walk(tree):
|
||||||
if hasattr(node,"lineno"):
|
if hasattr(node,"lineno"):
|
||||||
del node.lineno
|
del node.lineno
|
||||||
|
|
|
@ -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.
|
|
@ -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
|
static inline bool
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue