From: Nikita Popov Date: Sat, 30 Apr 2016 10:27:36 +0000 (+0200) Subject: Mark all $php_errormsg as refs to inhibit optimization X-Git-Tag: php-7.1.0alpha1~231 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0615c59a4fef83e0d90384c5f5664e72874c680c;p=php Mark all $php_errormsg as refs to inhibit optimization --- diff --git a/Zend/tests/php_errormsg_misoptimization.phpt b/Zend/tests/php_errormsg_misoptimization.phpt new file mode 100644 index 0000000000..c121c1021a --- /dev/null +++ b/Zend/tests/php_errormsg_misoptimization.phpt @@ -0,0 +1,20 @@ +--TEST-- +The variable $php_errormsg shouldn't be optimized as it may be unpredictably modified +--INI-- +track_errors=1 +--FILE-- + +--EXPECTF-- +Notice: Undefined variable: undef in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +int(1) diff --git a/ext/opcache/Optimizer/zend_inference.c b/ext/opcache/Optimizer/zend_inference.c index 0b2d7f47dd..b853a2e55c 100644 --- a/ext/opcache/Optimizer/zend_inference.c +++ b/ext/opcache/Optimizer/zend_inference.c @@ -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); }