]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-115420: Fix translation of exception hander targets by _testinternalcapi.optimize_...
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Thu, 15 Feb 2024 14:32:52 +0000 (14:32 +0000)
committerGitHub <noreply@github.com>
Thu, 15 Feb 2024 14:32:52 +0000 (14:32 +0000)
Lib/test/test_peepholer.py
Misc/NEWS.d/next/Tests/2024-02-13-18-24-04.gh-issue-115420.-dlzfI.rst [new file with mode: 0644]
Python/flowgraph.c

index 2ea186c85c8823e6e9a30284a93ee9a0f3a5bbc9..dffedd0b1fc4767e9123f09678a9d326af68b99b 100644 (file)
@@ -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 (file)
index 0000000..1442ada
--- /dev/null
@@ -0,0 +1,2 @@
+Fix translation of exception hander targets by
+``_testinternalcapi.optimize_cfg``.
index 1a648edf0880c02104a8f7e994227c234ce99cf6..4d9ba9eceb86373e18baa6edc66c285f596faced 100644 (file)
@@ -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(