diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-06-07 22:01:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-07 22:01:20 (GMT) |
commit | 3be7e91d037059dd98c175f48620191b538b9731 (patch) | |
tree | 7f9c1b19235cab66fd6b9424209ff5a30ff85993 | |
parent | 6238174e47a046dd6feb09ef4dd1bb55605ea0ad (diff) | |
download | cpython-3be7e91d037059dd98c175f48620191b538b9731.zip cpython-3be7e91d037059dd98c175f48620191b538b9731.tar.gz cpython-3be7e91d037059dd98c175f48620191b538b9731.tar.bz2 |
[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 4fc82b6d3b99f873179937215833e7a573ca7876)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
-rw-r--r-- | Lib/test/test_compile.py | 10 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2024-06-07-16-09-04.gh-issue-120225.kuYf9t.rst | 1 | ||||
-rw-r--r-- | Python/flowgraph.c | 8 |
3 files changed, 13 insertions, 6 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 1f4368b..410cdce 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -1409,6 +1409,16 @@ class TestSpecifics(unittest.TestCase): 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} + case []: + pass + [[]] @requires_debug_ranges() class TestSourcePositions(unittest.TestCase): diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-06-07-16-09-04.gh-issue-120225.kuYf9t.rst b/Misc/NEWS.d/next/Core and Builtins/2024-06-07-16-09-04.gh-issue-120225.kuYf9t.rst new file mode 100644 index 0000000..d00b9aa --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-06-07-16-09-04.gh-issue-120225.kuYf9t.rst @@ -0,0 +1 @@ +Fix crash in compiler on empty block at end of exception handler. diff --git a/Python/flowgraph.c b/Python/flowgraph.c index 8376802..b43cb6b 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -2276,15 +2276,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; b->b_next = explicit_jump; /* set target */ |