https://github.com/python/cpython/commit/3e7fff9d09cc502dbe0de4808291ff48b2ffdc11 commit: 3e7fff9d09cc502dbe0de4808291ff48b2ffdc11 branch: 3.14 author: Kirill Podoprigora <[email protected]> committer: Eclips4 <[email protected]> date: 2026-11-11T00:18:22Z summary:
[3.14] gh-159054: Check `basicblock_addop()` failure in `push_cold_blocks_to_end()` (GH-159057) (#161776) (cherry picked from commit e0d1ef25476875317be6e5ee74e1f254eeb49126) Co-authored-by: Pengyu <[email protected]> files: A Misc/NEWS.d/next/Core_and_Builtins/2026-10-09-18-27-12.gh-issue-159054.YUCTvG.rst M Lib/test/test_compile.py M Python/flowgraph.c diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 91d1365a0a21ba..0c151f850115d1 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -39,6 +39,27 @@ def test_no_ending_newline(self): def test_empty(self): compile("", "<test>", "exec") + @support.requires_subprocess() + @support.nomemtest + def test_push_cold_blocks_to_end_allocation_failure(self): + code = textwrap.dedent(""" + from test import support + + source = "async def f():\\n await x\\n" + for n in range(1, 1000): + with support.inject_memory_error_cm(n, n + 1): + try: + compile(source, "<test>", "exec") + except MemoryError: + continue + break + else: + raise AssertionError("compile() never succeeded") + if n == 1: + raise AssertionError("no MemoryError raised") + """) + script_helper.assert_python_ok('-c', code) + def test_other_newlines(self): compile("\r\n", "<test>", "exec") compile("\r", "<test>", "exec") diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-09-18-27-12.gh-issue-159054.YUCTvG.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-09-18-27-12.gh-issue-159054.YUCTvG.rst new file mode 100644 index 00000000000000..eaa01aa05435a7 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-09-18-27-12.gh-issue-159054.YUCTvG.rst @@ -0,0 +1,2 @@ +Fixed a crash when an allocation failure occurred while compiling code +containing cold blocks. diff --git a/Python/flowgraph.c b/Python/flowgraph.c index 4aa72cbf3b99b7..3aaa1f7a44e817 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -3452,8 +3452,9 @@ push_cold_blocks_to_end(cfg_builder *g) { if (!IS_LABEL(b->b_next->b_label)) { b->b_next->b_label.id = next_lbl++; } - basicblock_addop(explicit_jump, JUMP_NO_INTERRUPT, b->b_next->b_label.id, - NO_LOCATION); + RETURN_IF_ERROR( + basicblock_addop(explicit_jump, JUMP_NO_INTERRUPT, + b->b_next->b_label.id, NO_LOCATION)); explicit_jump->b_cold = 1; explicit_jump->b_next = b->b_next; explicit_jump->b_predecessors = 1; _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
