For now, don't treat FE_FETCH op2 as no-val use. See GH-4982.
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;
}
--- /dev/null
+--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)