]> granicus.if.org Git - php/commitdiff
Fix pi node removal when removing predecessor
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 1 Sep 2020 10:22:56 +0000 (12:22 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 1 Sep 2020 10:25:00 +0000 (12:25 +0200)
We can't just remove the uses, we need to replace uses.

The test case only fails on master with SSA integrity violations,
but I believe the root issue also existed previously.

Zend/tests/remove_predecessor_of_pi_node.phpt [new file with mode: 0644]
ext/opcache/Optimizer/zend_ssa.c

diff --git a/Zend/tests/remove_predecessor_of_pi_node.phpt b/Zend/tests/remove_predecessor_of_pi_node.phpt
new file mode 100644 (file)
index 0000000..2346d5a
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Regression test for incorrect update of pi node users when removing a predecessor block
+--FILE--
+<?php
+
+function test() {
+    for (; $n--; )
+        C;
+}
+test();
+
+?>
+--EXPECTF--
+Notice: Undefined variable: n in %s on line %d
index fdc383128b898d67a6124c2ea7d7e63e1c50b1ec..89dfe57914a470aa846b6a719fcb088be158ba57 100644 (file)
@@ -1388,7 +1388,7 @@ void zend_ssa_remove_predecessor(zend_ssa *ssa, int from, int to) /* {{{ */
        for (phi = next_ssa_block->phis; phi; phi = phi->next) {
                if (phi->pi >= 0) {
                        if (phi->pi == from) {
-                               zend_ssa_remove_uses_of_var(ssa, phi->ssa_var);
+                               zend_ssa_rename_var_uses(ssa, phi->ssa_var, phi->sources[0], /* update_types */ 0);
                                zend_ssa_remove_phi(ssa, phi);
                        }
                } else {