From 73f13f439b3e10cca9b17e7f15c06e7fd11eb6c9 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 10 Dec 2013 17:04:17 +0400 Subject: [PATCH] Fixed bug #66251 (Constants get statically bound at compile time when Optimized) --- ext/opcache/Optimizer/pass1_5.c | 42 ++++++++++++++++++--------------- ext/opcache/tests/bug66251.phpt | 17 +++++++++++++ 2 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 ext/opcache/tests/bug66251.phpt diff --git a/ext/opcache/Optimizer/pass1_5.c b/ext/opcache/Optimizer/pass1_5.c index bd8af47a95e..f173c3f657e 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 00000000000..23a5165234d --- /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-- + +--FILE-- + +--EXPECTF-- +Notice: Use of undefined constant A - assumed 'A' in %sbug66251.php on line 4 +A=A