summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-17 15:07:20 (GMT)
committerGitHub <noreply@github.com>2024-06-17 15:07:20 (GMT)
commit61a2229005749dac782fc2e950d3f4fd25ed2181 (patch)
tree09fc04b50bbf2c3de29bcc1f2a1a394f499bc9ee /Lib
parent7c47f93dff878bdc43f5162dd878cbb375711570 (diff)
downloadcpython-61a2229005749dac782fc2e950d3f4fd25ed2181.zip
cpython-61a2229005749dac782fc2e950d3f4fd25ed2181.tar.gz
cpython-61a2229005749dac782fc2e950d3f4fd25ed2181.tar.bz2
[3.13] gh-120367: fix removal of redundant NOPs and jumps after reordering hot-cold blocks (GH-120425) (#120621)
gh-120367: fix removal of redundant NOPs and jumps after reordering hot-cold blocks (GH-120425) (cherry picked from commit 21866c8ed296524f0ca175c0f55b43744c2b30df) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_compile.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 410cdce..417bc8c 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -502,6 +502,33 @@ class TestSpecifics(unittest.TestCase):
with self.assertRaisesRegex(TypeError, "NamedExpr target must be a Name"):
compile(ast.fix_missing_locations(m), "<file>", "exec")
+ def test_compile_redundant_jumps_and_nops_after_moving_cold_blocks(self):
+ # See gh-120367
+ code=textwrap.dedent("""
+ try:
+ pass
+ except:
+ pass
+ else:
+ match name_2:
+ case b'':
+ pass
+ finally:
+ something
+ """)
+
+ tree = ast.parse(code)
+
+ # make all instructions 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_ast(self):
fname = __file__
if fname.lower().endswith('pyc'):