diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2024-02-15 14:32:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-15 14:32:52 (GMT) |
commit | f42e112fd86edb5507a38a2eb850d0ebc6bc27a2 (patch) | |
tree | 9b6eed319f743d7ce2e5a3ef6c4378015cfa0837 | |
parent | 3a9e67a9fdb4fad13bf42df6eb91126ab2ef45a1 (diff) | |
download | cpython-f42e112fd86edb5507a38a2eb850d0ebc6bc27a2.zip cpython-f42e112fd86edb5507a38a2eb850d0ebc6bc27a2.tar.gz cpython-f42e112fd86edb5507a38a2eb850d0ebc6bc27a2.tar.bz2 |
gh-115420: Fix translation of exception hander targets by _testinternalcapi.optimize_cfg. (#115425)
-rw-r--r-- | Lib/test/test_peepholer.py | 16 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Tests/2024-02-13-18-24-04.gh-issue-115420.-dlzfI.rst | 2 | ||||
-rw-r--r-- | Python/flowgraph.c | 2 |
3 files changed, 19 insertions, 1 deletions
diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index 2ea186c..dffedd0 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -1065,6 +1065,22 @@ class DirectCfgOptimizerTests(CfgOptimizationTestCase): ] self.cfg_optimization_test(insts, expected_insts, consts=list(range(5))) + def test_except_handler_label(self): + insts = [ + ('SETUP_FINALLY', handler := self.Label(), 10), + ('POP_BLOCK', 0, -1), + ('RETURN_CONST', 1, 11), + handler, + ('RETURN_CONST', 2, 12), + ] + expected_insts = [ + ('SETUP_FINALLY', handler := self.Label(), 10), + ('RETURN_CONST', 1, 11), + handler, + ('RETURN_CONST', 2, 12), + ] + self.cfg_optimization_test(insts, expected_insts, consts=list(range(5))) + def test_no_unsafe_static_swap(self): # We can't change order of two stores to the same location insts = [ diff --git a/Misc/NEWS.d/next/Tests/2024-02-13-18-24-04.gh-issue-115420.-dlzfI.rst b/Misc/NEWS.d/next/Tests/2024-02-13-18-24-04.gh-issue-115420.-dlzfI.rst new file mode 100644 index 0000000..1442ada --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2024-02-13-18-24-04.gh-issue-115420.-dlzfI.rst @@ -0,0 +1,2 @@ +Fix translation of exception hander targets by +``_testinternalcapi.optimize_cfg``. diff --git a/Python/flowgraph.c b/Python/flowgraph.c index 1a648ed..4d9ba9e 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -2729,7 +2729,7 @@ _PyCfg_ToInstructionSequence(cfg_builder *g, _PyCompile_InstructionSequence *seq RETURN_IF_ERROR(_PyCompile_InstructionSequence_UseLabel(seq, b->b_label.id)); for (int i = 0; i < b->b_iused; i++) { cfg_instr *instr = &b->b_instr[i]; - if (OPCODE_HAS_JUMP(instr->i_opcode)) { + if (OPCODE_HAS_JUMP(instr->i_opcode) || is_block_push(instr)) { instr->i_oparg = instr->i_target->b_label.id; } RETURN_IF_ERROR( |