summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-18 22:34:07 (GMT)
committerGitHub <noreply@github.com>2024-06-18 22:34:07 (GMT)
commit50fa775e6821b8b242f5709c36c62e7c4fb2c522 (patch)
tree80a3d0ecf3676db3d64ebb7f591ca027154839dd
parent07145ddf19bc423e83d0290095833bc95861fc2f (diff)
downloadcpython-50fa775e6821b8b242f5709c36c62e7c4fb2c522.zip
cpython-50fa775e6821b8b242f5709c36c62e7c4fb2c522.tar.gz
cpython-50fa775e6821b8b242f5709c36c62e7c4fb2c522.tar.bz2
[3.13] gh-120367: fix bug where compiler detects redundant jump after pseudo op replacement (GH-120714) (#120716)
-rw-r--r--Lib/test/test_compile.py27
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2024-06-18-21-34-30.gh-issue-120367.zDwffP.rst1
-rw-r--r--Python/flowgraph.c2
3 files changed, 28 insertions, 2 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 417bc8c..6be6155 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -519,7 +519,32 @@ class TestSpecifics(unittest.TestCase):
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
diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-06-18-21-34-30.gh-issue-120367.zDwffP.rst b/Misc/NEWS.d/next/Core and Builtins/2024-06-18-21-34-30.gh-issue-120367.zDwffP.rst
new file mode 100644
index 0000000..087640e
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2024-06-18-21-34-30.gh-issue-120367.zDwffP.rst
@@ -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.
diff --git a/Python/flowgraph.c b/Python/flowgraph.c
index 17b62b6..b8d3f06 100644
--- a/Python/flowgraph.c
+++ b/Python/flowgraph.c
@@ -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