summaryrefslogtreecommitdiff
path: root/ext/opcache
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2013-12-10 17:04:17 +0400
committerDmitry Stogov <dmitry@zend.com>2013-12-10 17:04:17 +0400
commit73f13f439b3e10cca9b17e7f15c06e7fd11eb6c9 (patch)
tree1e5c4ca9da5c89e146e80924d27155f8cd0f313a /ext/opcache
parent1e161a9c0fc215344998674401122f62077c47af (diff)
downloadphp-git-73f13f439b3e10cca9b17e7f15c06e7fd11eb6c9.tar.gz
Fixed bug #66251 (Constants get statically bound at compile time when Optimized)
Diffstat (limited to 'ext/opcache')
-rw-r--r--ext/opcache/Optimizer/pass1_5.c42
-rw-r--r--ext/opcache/tests/bug66251.phpt17
2 files changed, 40 insertions, 19 deletions
diff --git a/ext/opcache/Optimizer/pass1_5.c b/ext/opcache/Optimizer/pass1_5.c
index bd8af47a95..f173c3f657 100644
--- a/ext/opcache/Optimizer/pass1_5.c
+++ b/ext/opcache/Optimizer/pass1_5.c
@@ -321,6 +321,27 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
break;
case ZEND_DO_FCALL:
+ /* define("name", scalar); */
+ if (collect_constants &&
+ opline->extended_value == 2 &&
+ ZEND_OP1_TYPE(opline) == IS_CONST &&
+ Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING &&
+ Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("define")-1 &&
+ zend_binary_strcasecmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)), "define", sizeof("define")-1) == 0 &&
+ (opline-1)->opcode == ZEND_SEND_VAL &&
+ ZEND_OP1_TYPE(opline-1) == IS_CONST &&
+ (Z_TYPE(ZEND_OP1_LITERAL(opline-1)) <= IS_BOOL ||
+ Z_TYPE(ZEND_OP1_LITERAL(opline-1)) == IS_STRING) &&
+ (opline-2)->opcode == ZEND_SEND_VAL &&
+ ZEND_OP1_TYPE(opline-2) == IS_CONST &&
+ Z_TYPE(ZEND_OP1_LITERAL(opline-2)) == IS_STRING) {
+ zend_optimizer_collect_constant(constants, &ZEND_OP1_LITERAL(opline-2), &ZEND_OP1_LITERAL(opline-1));
+ break;
+ } else {
+ /* don't colllect constants after any other function call */
+ collect_constants = 0;
+ }
+
/* pre-evaluate constant functions:
defined(x)
constant(x)
@@ -428,25 +449,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
MAKE_NOP(opline);
}
}
- break;
- }
-
- /* define("name", scalar); */
- if (collect_constants &&
- opline->extended_value == 2 &&
- ZEND_OP1_TYPE(opline) == IS_CONST &&
- Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING &&
- Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("define")-1 &&
- zend_binary_strcasecmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)), "define", sizeof("define")-1) == 0 &&
- (opline-1)->opcode == ZEND_SEND_VAL &&
- ZEND_OP1_TYPE(opline-1) == IS_CONST &&
- (Z_TYPE(ZEND_OP1_LITERAL(opline-1)) <= IS_BOOL ||
- Z_TYPE(ZEND_OP1_LITERAL(opline-1)) == IS_STRING) &&
- (opline-2)->opcode == ZEND_SEND_VAL &&
- ZEND_OP1_TYPE(opline-2) == IS_CONST &&
- Z_TYPE(ZEND_OP1_LITERAL(opline-2)) == IS_STRING) {
- zend_optimizer_collect_constant(constants, &ZEND_OP1_LITERAL(opline-2), &ZEND_OP1_LITERAL(opline-1));
- }
+ }
break;
#if ZEND_EXTENSION_API_NO > PHP_5_2_X_API_NO
case ZEND_DECLARE_CONST:
@@ -487,6 +490,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
case ZEND_FE_RESET:
case ZEND_FE_FETCH:
case ZEND_NEW:
+ case ZEND_DO_FCALL_BY_NAME:
#if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
case ZEND_JMP_SET:
#endif
diff --git a/ext/opcache/tests/bug66251.phpt b/ext/opcache/tests/bug66251.phpt
new file mode 100644
index 0000000000..23a5165234
--- /dev/null
+++ b/ext/opcache/tests/bug66251.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #66251 (Constants get statically bound at compile time when Optimized)
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+--SKIPIF--
+<?php if (!extension_loaded('Zend OPcache') || php_sapi_name() != "cli") die("skip CLI only"); ?>
+--FILE--
+<?php
+printf ("A=%s\n", getA());
+const A="hello";
+function getA() {return A;}
+?>
+--EXPECTF--
+Notice: Use of undefined constant A - assumed 'A' in %sbug66251.php on line 4
+A=A