8000 [3.12] gh-109719: Fix missing jump target labels when compiler reorde… · python/cpython@633bd6e · GitHub
[go: up one dir, main page]

Skip to content

Commit 633bd6e

Browse files
[3.12] gh-109719: Fix missing jump target labels when compiler reorders cold/warm blocks (GH-109734) (#109749)
gh-109719: Fix missing jump target labels when compiler reorders cold/warm blocks (GH-109734) (cherry picked from commit 7c55399) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
1 parent f6287bd commit 633bd6e

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

Lib/test/test_compile.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,17 @@ def f():
12251225
except:
12261226
pass
12271227

1228+
def test_cold_block_moved_to_end(self):
1229+
# See gh-109719
1230+
def f():
1231+
while name:
1232+
try:
1233+
break
1234+
except:
1235+
pass
1236+
else:
1237+
1 if 1 else 1
1238+
12281239

12291240
@requires_debug_ranges()
12301241
class TestSourcePositions(unittest.TestCase):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix missing jump target labels when compiler reorders cold/warm blocks.

Python/flowgraph.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,8 @@ push_cold_blocks_to_end(cfg_builder *g, int code_flags) {
19451945
}
19461946
RETURN_IF_ERROR(mark_cold(entryblock));
19471947

1948+
int next_lbl = get_max_label(g->g_entryblock) + 1;
1949+
19481950
/* If we have a cold block with fallthrough to a warm block, add */
19491951
/* an explicit jump instead of fallthrough */
19501952
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
@@ -1953,6 +1955,9 @@ push_cold_blocks_to_end(cfg_builder *g, int code_flags) {
19531955
if (explicit_jump == NULL) {
19541956
return ERROR;
19551957
}
1958+
if (!IS_LABEL(b->b_next->b_label)) {
1959+
b->b_next->b_label.id = next_lbl++;
1960+
}
19561961
basicblock_addop(explicit_jump, JUMP, b->b_next->b_label.id, NO_LOCATION);
19571962
explicit_jump->b_cold = 1;
19581963
explicit_jump->b_next = b->b_next;

0 commit comments

Comments
 (0)
0