Skip to content

Commit 3be7e91

Browse files
[3.13] gh-120225: fix crash in compiler on empty block at end of exception handler (GH-120235) (#120249)
gh-120225: fix crash in compiler on empty block at end of exception handler (GH-120235) (cherry picked from commit 4fc82b6) Co-authored-by: Irit Katriel <[email protected]>
1 parent 6238174 commit 3be7e91

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
@@ -2276,15 +2276,11 @@ push_cold_blocks_to_end(cfg_builder *g) {
22762276
if (!IS_LABEL(b->b_next->b_label)) {
22772277
b->b_next->b_label.id = next_lbl++;
22782278
}
2279-
cfg_instr *prev_instr = basicblock_last_instr(b);
2280-
// b cannot be empty because at the end of an exception handler
2281-
// there is always a POP_EXCEPT + RERAISE/RETURN
2282-
assert(prev_instr);
2283-
22842279
basicblock_addop(explicit_jump, JUMP_NO_INTERRUPT, b->b_next->b_label.id,
2285-
prev_instr->i_loc);
2280+
NO_LOCATION);
22862281
explicit_jump->b_cold = 1;
22872282
explicit_jump->b_next = b->b_next;
2283+
explicit_jump->b_predecessors = 1;
22882284
b->b_next = explicit_jump;
22892285

22902286
/* set target */

0 commit comments

Comments
 (0)