]> granicus.if.org Git - php/commitdiff
Mark all $php_errormsg as refs to inhibit optimization
authorNikita Popov <nikic@php.net>
Sat, 30 Apr 2016 10:27:36 +0000 (12:27 +0200)
committerNikita Popov <nikic@php.net>
Sat, 30 Apr 2016 10:34:01 +0000 (12:34 +0200)
Zend/tests/php_errormsg_misoptimization.phpt [new file with mode: 0644]
ext/opcache/Optimizer/zend_inference.c

diff --git a/Zend/tests/php_errormsg_misoptimization.phpt b/Zend/tests/php_errormsg_misoptimization.phpt
new file mode 100644 (file)
index 0000000..c121c10
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+The variable $php_errormsg shouldn't be optimized as it may be unpredictably modified
+--INI--
+track_errors=1
+--FILE--
+<?php
+
+function test() {
+    $php_errormsg = 1;
+    echo $undef;
+    var_dump($php_errormsg + 1);
+}
+test();
+
+?>
+--EXPECTF--
+Notice: Undefined variable: undef in %s on line %d
+
+Warning: A non-numeric value encountered in %s on line %d
+int(1)
index 0b2d7f47dd372d404e0fb5b4b3173c67d5368743..b853a2e55c82e6f14860fd545d7429a85edd69d3 100644 (file)
@@ -4152,6 +4152,19 @@ static int zend_infer_types(const zend_op_array *op_array, const zend_script *sc
        /* Narrowing integer initialization to doubles */
        zend_type_narrowing(op_array, script, ssa);
 
+       for (j = 0; j < op_array->last_var; j++) {
+               if (zend_string_equals_literal(op_array->vars[j], "php_errormsg")) {
+                       /* Mark all SSA vars for $php_errormsg as references,
+                        * to make sure we don't optimize it. */
+                       int i;
+                       for (i = 0; i < ssa_vars_count; i++) {
+                               if (ssa->vars[i].var == j) {
+                                       ssa_var_info[i].type |= MAY_BE_REF | MAY_BE_ANY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
+                               }
+                       }
+               }
+       }
+
        if (ZEND_FUNC_INFO(op_array)) {
                zend_func_return_info(op_array, script, 1, 0, &ZEND_FUNC_INFO(op_array)->return_info);
        }