[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 7c55399172)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2023-09-24 04:51:30 -07:00 committed by GitHub
parent f6287bd46f
commit 633bd6e428
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View file

@ -1225,6 +1225,17 @@ class TestSpecifics(unittest.TestCase):
except: except:
pass pass
def test_cold_block_moved_to_end(self):
# See gh-109719
def f():
while name:
try:
break
except:
pass
else:
1 if 1 else 1
@requires_debug_ranges() @requires_debug_ranges()
class TestSourcePositions(unittest.TestCase): class TestSourcePositions(unittest.TestCase):

View file

@ -0,0 +1 @@
Fix missing jump target labels when compiler reorders cold/warm blocks.

View file

@ -1945,6 +1945,8 @@ push_cold_blocks_to_end(cfg_builder *g, int code_flags) {
} }
RETURN_IF_ERROR(mark_cold(entryblock)); RETURN_IF_ERROR(mark_cold(entryblock));
int next_lbl = get_max_label(g->g_entryblock) + 1;
/* If we have a cold block with fallthrough to a warm block, add */ /* If we have a cold block with fallthrough to a warm block, add */
/* an explicit jump instead of fallthrough */ /* an explicit jump instead of fallthrough */
for (basicblock *b = entryblock; b != NULL; b = b->b_next) { 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) {
if (explicit_jump == NULL) { if (explicit_jump == NULL) {
return ERROR; return ERROR;
} }
if (!IS_LABEL(b->b_next->b_label)) {
b->b_next->b_label.id = next_lbl++;
}
basicblock_addop(explicit_jump, JUMP, b->b_next->b_label.id, NO_LOCATION); basicblock_addop(explicit_jump, JUMP, b->b_next->b_label.id, NO_LOCATION);
explicit_jump->b_cold = 1; explicit_jump->b_cold = 1;
explicit_jump->b_next = b->b_next; explicit_jump->b_next = b->b_next;