gh-115420: Fix translation of exception hander targets by _testinternalcapi.optimize_cfg. (#115425)

This commit is contained in:
Irit Katriel 2024-02-15 14:32:52 +00:00 committed by GitHub
parent 3a9e67a9fd
commit f42e112fd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 1 deletions

View 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 = [

View file

@ -0,0 +1,2 @@
Fix translation of exception hander targets by
``_testinternalcapi.optimize_cfg``.

View 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(