Skip to content

Commit 5008543

Browse files
iritkatrielpull[bot]
authored andcommitted
gh-120225: fix crash in compiler on empty block at end of exception handler (#120235)
1 parent 30a8875 commit 5008543

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Lib/test/test_compile.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,16 @@ def f():
14091409
for kw in ("except", "except*"):
14101410
exec(code % kw, g, l);
14111411

1412+
def test_regression_gh_120225(self):
1413+
async def name_4():
1414+
match b'':
1415+
case True:
1416+
pass
1417+
case name_5 if f'e':
1418+
{name_3: name_4 async for name_2 in name_5}
1419+
case []:
1420+
pass
1421+
[[]]
14121422

14131423
@requires_debug_ranges()
14141424
class TestSourcePositions(unittest.TestCase):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix crash in compiler on empty block at end of exception handler.

Python/flowgraph.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,15 +2304,11 @@ push_cold_blocks_to_end(cfg_builder *g) {
23042304
if (!IS_LABEL(b->b_next->b_label)) {
23052305
b->b_next->b_label.id = next_lbl++;
23062306
}
2307-
cfg_instr *prev_instr = basicblock_last_instr(b);
2308-
// b cannot be empty because at the end of an exception handler
2309-
// there is always a POP_EXCEPT + RERAISE/RETURN
2310-
assert(prev_instr);
2311-
23122307
basicblock_addop(explicit_jump, JUMP_NO_INTERRUPT, b->b_next->b_label.id,
2313-
prev_instr->i_loc);
2308+
NO_LOCATION);
23142309
explicit_jump->b_cold = 1;
23152310
explicit_jump->b_next = b->b_next;
2311+
explicit_jump->b_predecessors = 1;
23162312
b->b_next = explicit_jump;
23172313

23182314
/* set target */

0 commit comments

Comments
 (0)