]> granicus.if.org Git - php/commitdiff
Fix block removal if there are duplicate successors
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 22 Jul 2017 12:53:23 +0000 (14:53 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 22 Jul 2017 12:53:23 +0000 (14:53 +0200)
ext/opcache/Optimizer/zend_ssa.c
ext/opcache/tests/block_removal_with_duplicate_successors.phpt [new file with mode: 0644]

index b0c087b1bdffaf541e54335bcbe0b7a6fe51b5ec..a82d7ff2251730e39d6c1a1aa435b331f3250eb8 100644 (file)
@@ -1382,7 +1382,12 @@ void zend_ssa_remove_block(zend_op_array *op_array, zend_ssa *ssa, int i) /* {{{
                                break;
                        }
                }
-               ZEND_ASSERT(pred_offset != -1);
+
+               /* If there are duplicate successors, the predecessors may have been removed in
+                * a previous iteration already. */
+               if (pred_offset == -1) {
+                       continue;
+               }
 
                /* For phis in successor blocks, remove the operands associated with this block */
                for (phi = next_ssa_block->phis; phi; phi = phi->next) {
diff --git a/ext/opcache/tests/block_removal_with_duplicate_successors.phpt b/ext/opcache/tests/block_removal_with_duplicate_successors.phpt
new file mode 100644 (file)
index 0000000..750a169
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Removing a block that has duplicate successors
+--FILE--
+<?php
+function test($foo) {
+    $bar = 0;
+    if ($bar === 1 && $foo && PHP_SAPI !== 'cli') {
+        echo "foo\n";
+    }
+    echo "bar\n";
+}
+test(1);
+?>
+--EXPECT--
+bar