com php-src: Mark all $php_errormsg as refs to inhi bit optimization: Zend/tests/php_errormsg_misoptimiza tion.phpt
ext/opcache/Optimizer/zend_inference.c
| From: | Nikita Popov | Date: | Sat, 30 Apr 2016 10:34:01 +0000 |
| Subject: | com php-src: Mark all $php_errormsg as refs to inhi bit optimization: Zend/tests/php_errormsg_misoptimiza tion.phpt ext/opcache/Optimizer/zend_inference.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-91979@lists.php.net to get a copy of this message | ||
Commit: 0615c59a4fef83e0d90384c5f5664e72874c680c
Author: Nikita Popov <nikic@php.net> Sat, 30 Apr 2016 12:27:36 +0200
Parents: bdfa6aeebba43eee2c12d60b8add869af447a91a
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=0615c59a4fef83e0d90384c5f5664e72874c680c
Log:
Mark all $php_errormsg as refs to inhibit optimization
Changed paths:
A Zend/tests/php_errormsg_misoptimization.phpt
M ext/opcache/Optimizer/zend_inference.c
Diff:
diff --git a/Zend/tests/php_errormsg_misoptimization.phpt
b/Zend/tests/php_errormsg_misoptimization.phpt
new file mode 100644
index 0000000..c121c10
--- /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--
+<?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)
diff --git a/ext/opcache/Optimizer/zend_inference.c b/ext/opcache/Optimizer/zend_inference.c
index 0b2d7f4..b853a2e 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);
}