From d8831701e4f8357e3fac3777821c53fd6fedeb00 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Tue, 18 Jun 2024 22:28:21 +0100 Subject: [PATCH 1/3] gh-120367: remove redundant jumps after pseudo op replacement --- Lib/test/test_compile.py | 27 ++++++++++++++++++++++++++- Python/flowgraph.c | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 40295236eb7d92..e3e86b89246648 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -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), "", "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/Python/flowgraph.c b/Python/flowgraph.c index 6f30dfcd33e0b4..8c1c20a0583c8c 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -2389,7 +2389,7 @@ convert_pseudo_ops(cfg_builder *g) } } } - return remove_redundant_nops(g); + return remove_redundant_nops_and_jumps(g); } static inline bool From 60ac5d2a72203a57405e9ba2ba9a592df5465d24 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 21:34:35 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2024-06-18-21-34-30.gh-issue-120367.zDwffP.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-06-18-21-34-30.gh-issue-120367.zDwffP.rst 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 00000000000000..8d9663c403a155 --- /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. From 8a80635c1c2656bde14e332c1d46a81d64e981c0 Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Tue, 18 Jun 2024 22:45:18 +0100 Subject: [PATCH 3/3] formatting --- .../2024-06-18-21-34-30.gh-issue-120367.zDwffP.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 8d9663c403a155..087640e5400b98 100644 --- 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 @@ -1 +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. +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.