]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-95922: compiler's eliminate_empty_basic_blocks ignores the last block of the compi...
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Fri, 12 Aug 2022 15:35:09 +0000 (16:35 +0100)
committerGitHub <noreply@github.com>
Fri, 12 Aug 2022 15:35:09 +0000 (16:35 +0100)
Misc/NEWS.d/next/Core and Builtins/2022-08-12-13-04-25.gh-issue-95922.YNCtyX.rst [new file with mode: 0644]
Python/compile.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-08-12-13-04-25.gh-issue-95922.YNCtyX.rst b/Misc/NEWS.d/next/Core and Builtins/2022-08-12-13-04-25.gh-issue-95922.YNCtyX.rst
new file mode 100644 (file)
index 0000000..277d35d
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed bug where the compiler's ``eliminate_empty_basic_blocks`` function
+ignores the last block of the code unit.
index a971b09c530451e29aad8dae96282d68752e7c58..3dec7b5edfb5e9f9b4a8551a4dcd79ac44c31f43 100644 (file)
@@ -9349,17 +9349,13 @@ eliminate_empty_basic_blocks(basicblock *entryblock) {
     /* Eliminate empty blocks */
     for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
         basicblock *next = b->b_next;
-        if (next) {
-            while (next->b_iused == 0 && next->b_next) {
-                next = next->b_next;
-            }
-            b->b_next = next;
+        while (next && next->b_iused == 0) {
+            next = next->b_next;
         }
+        b->b_next = next;
     }
     for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
-        if (b->b_iused == 0) {
-            continue;
-        }
+        assert(b->b_iused > 0);
         for (int i = 0; i < b->b_iused; i++) {
             struct instr *instr = &b->b_instr[i];
             if (HAS_TARGET(instr->i_opcode)) {
@@ -9368,6 +9364,7 @@ eliminate_empty_basic_blocks(basicblock *entryblock) {
                     target = target->b_next;
                 }
                 instr->i_target = target;
+                assert(instr->i_target && instr->i_target->b_iused > 0);
             }
         }
     }