Skip to content

Commit 41757bf

Browse files
authored
gh-95922: compiler's eliminate_empty_basic_blocks ignores the last block of the compilation unit (GH-95924)
1 parent 7da4937 commit 41757bf

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed bug where the compiler's ``eliminate_empty_basic_blocks`` function
2+
ignores the last block of the code unit.

Python/compile.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9349,17 +9349,13 @@ eliminate_empty_basic_blocks(basicblock *entryblock) {
93499349
/* Eliminate empty blocks */
93509350
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
93519351
basicblock *next = b->b_next;
9352-
if (next) {
9353-
while (next->b_iused == 0 && next->b_next) {
9354-
next = next->b_next;
9355-
}
9356-
b->b_next = next;
9352+
while (next && next->b_iused == 0) {
9353+
next = next->b_next;
93579354
}
9355+
b->b_next = next;
93589356
}
93599357
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
9360-
if (b->b_iused == 0) {
9361-
continue;
9362-
}
9358+
assert(b->b_iused > 0);
93639359
for (int i = 0; i < b->b_iused; i++) {
93649360
struct instr *instr = &b->b_instr[i];
93659361
if (HAS_TARGET(instr->i_opcode)) {
@@ -9368,6 +9364,7 @@ eliminate_empty_basic_blocks(basicblock *entryblock) {
93689364
target = target->b_next;
93699365
}
93709366
instr->i_target = target;
9367+
assert(instr->i_target && instr->i_target->b_iused > 0);
93719368
}
93729369
}
93739370
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy