Fixed bug #66251 (Constants get statically bound at compile time when Optimized)

This commit is contained in:
Dmitry Stogov 2013-12-10 17:04:17 +04:00
parent 1e161a9c0f
commit 73f13f439b
2 changed files with 40 additions and 19 deletions

View File

@ -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

View File

@ -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