Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-120225: fix crash in compiler on empty block at end of exception handler #120235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,16 @@ def f():
for kw in ("except", "except*"):
exec(code % kw, g, l);

def test_regression_gh_120225(self):
async def name_4():
match b'':
case True:
pass
case name_5 if f'e':
{name_3: name_4 async for name_2 in name_5}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the exception handling block is coming from inlining this comprehension?

case []:
pass
[[]]

@requires_debug_ranges()
class TestSourcePositions(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash in compiler on empty block at end of exception handler.
8 changes: 2 additions & 6 deletions Python/flowgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -2304,15 +2304,11 @@ push_cold_blocks_to_end(cfg_builder *g) {
if (!IS_LABEL(b->b_next->b_label)) {
b->b_next->b_label.id = next_lbl++;
}
cfg_instr *prev_instr = basicblock_last_instr(b);
// b cannot be empty because at the end of an exception handler
// there is always a POP_EXCEPT + RERAISE/RETURN
assert(prev_instr);

basicblock_addop(explicit_jump, JUMP_NO_INTERRUPT, b->b_next->b_label.id,
prev_instr->i_loc);
NO_LOCATION);
explicit_jump->b_cold = 1;
explicit_jump->b_next = b->b_next;
explicit_jump->b_predecessors = 1;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was missing here - it is needed later for line number propagation to work.

b->b_next = explicit_jump;

/* set target */
Expand Down
Loading