]> granicus.if.org Git - php/commitdiff
Fix DCE with FE_FETCH
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 10 Dec 2019 08:00:09 +0000 (09:00 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 10 Dec 2019 08:00:09 +0000 (09:00 +0100)
For now, don't treat FE_FETCH op2 as no-val use. See GH-4982.

ext/opcache/Optimizer/zend_ssa.h
ext/opcache/tests/fe_fetch_dce.phpt [new file with mode: 0644]

index 4ee442dcab6d67c34ce481f60d1bf7eba7c2ffb5..4707e3807a87ffeed71f95f88982984cd7dc6fab 100644 (file)
@@ -217,9 +217,10 @@ static zend_always_inline zend_bool zend_ssa_is_no_val_use(const zend_op *opline
        if (opline->opcode == ZEND_ASSIGN || opline->opcode == ZEND_UNSET_CV) {
                return ssa_op->op1_use == var && ssa_op->op2_use != var;
        }
-       if (opline->opcode == ZEND_FE_FETCH_R) {
+       // TODO: Reenable this after changing the SSA structure.
+       /*if (opline->opcode == ZEND_FE_FETCH_R) {
                return ssa_op->op2_use == var && ssa_op->op1_use != var;
-       }
+       }*/
        if (ssa_op->result_use == var && opline->opcode != ZEND_ADD_ARRAY_ELEMENT) {
                return ssa_op->op1_use != var && ssa_op->op2_use != var;
        }
diff --git a/ext/opcache/tests/fe_fetch_dce.phpt b/ext/opcache/tests/fe_fetch_dce.phpt
new file mode 100644 (file)
index 0000000..f7ff020
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Incorrect DCE with FE_FETCH
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+--FILE--
+<?php
+
+function test() {
+    $a = ["3"];
+    $x = 1;
+    foreach ($a as $x) {
+        $x = 2.0;
+    }
+    var_dump($x);
+}
+test();
+
+?>
+--EXPECT--
+float(2)