[3.14] gh-137288: Fix bug where boolean expressions are not associated with the correct exception handler (GH-137310). (#137427)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
Irit Katriel 2025-08-12 10:56:37 +01:00 committed by GitHub
parent 019238ab18
commit 0ccf244a19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 27 additions and 2 deletions

View file

@ -3463,11 +3463,13 @@ convert_pseudo_conditional_jumps(cfg_builder *g)
instr->i_opcode = instr->i_opcode == JUMP_IF_FALSE ?
POP_JUMP_IF_FALSE : POP_JUMP_IF_TRUE;
location loc = instr->i_loc;
basicblock *except = instr->i_except;
cfg_instr copy = {
.i_opcode = COPY,
.i_oparg = 1,
.i_loc = loc,
.i_target = NULL,
.i_except = except,
};
RETURN_IF_ERROR(basicblock_insert_instruction(b, i++, &copy));
cfg_instr to_bool = {
@ -3475,6 +3477,7 @@ convert_pseudo_conditional_jumps(cfg_builder *g)
.i_oparg = 0,
.i_loc = loc,
.i_target = NULL,
.i_except = except,
};
RETURN_IF_ERROR(basicblock_insert_instruction(b, i++, &to_bool));
}
@ -3717,6 +3720,7 @@ insert_prefix_instructions(_PyCompile_CodeUnitMetadata *umd, basicblock *entrybl
.i_oparg = 0,
.i_loc = loc,
.i_target = NULL,
.i_except = NULL,
};
RETURN_IF_ERROR(basicblock_insert_instruction(entryblock, 0, &make_gen));
cfg_instr pop_top = {
@ -3724,6 +3728,7 @@ insert_prefix_instructions(_PyCompile_CodeUnitMetadata *umd, basicblock *entrybl
.i_oparg = 0,
.i_loc = loc,
.i_target = NULL,
.i_except = NULL,
};
RETURN_IF_ERROR(basicblock_insert_instruction(entryblock, 1, &pop_top));
}
@ -3754,6 +3759,7 @@ insert_prefix_instructions(_PyCompile_CodeUnitMetadata *umd, basicblock *entrybl
.i_oparg = oldindex,
.i_loc = NO_LOCATION,
.i_target = NULL,
.i_except = NULL,
};
if (basicblock_insert_instruction(entryblock, ncellsused, &make_cell) < 0) {
PyMem_RawFree(sorted);
@ -3770,6 +3776,7 @@ insert_prefix_instructions(_PyCompile_CodeUnitMetadata *umd, basicblock *entrybl
.i_oparg = nfreevars,
.i_loc = NO_LOCATION,
.i_target = NULL,
.i_except = NULL,
};
RETURN_IF_ERROR(basicblock_insert_instruction(entryblock, 0, &copy_frees));
}