summaryrefslogtreecommitdiff
path: root/ext/opcache
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2014-05-26 10:10:59 +0400
committerDmitry Stogov <dmitry@zend.com>2014-05-26 10:10:59 +0400
commit19be8b676cd8cc16af35dd47b8f74f750f40f694 (patch)
tree64e1ee6cf27b75c420084cd0d64de8d5301d8bf0 /ext/opcache
parent980c63651c65f4078f627409781b6d66e5834088 (diff)
downloadphp-git-19be8b676cd8cc16af35dd47b8f74f750f40f694.tar.gz
Fixed issue #183 (TMP_VAR is not only used once)
Diffstat (limited to 'ext/opcache')
-rw-r--r--ext/opcache/Optimizer/zend_optimizer.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c
index fd0f77dbc8..ae85c7bc86 100644
--- a/ext/opcache/Optimizer/zend_optimizer.c
+++ b/ext/opcache/Optimizer/zend_optimizer.c
@@ -284,20 +284,41 @@ static void replace_tmp_by_const(zend_op_array *op_array,
if (ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
ZEND_OP1(opline).var == var) {
- update_op1_const(op_array, opline, val TSRMLS_CC);
- /* TMP_VAR my be used only once */
- break;
+ /* In most cases IS_TMP_VAR operand may be used only once.
+ * The operands are usually destroyed by the opcode handler.
+ * ZEND_CASE is an exception, that keeps operand unchanged,
+ * and allows its reuse. The number of ZEND_CASE instructions
+ * usually terminated by ZEND_FREE that finally kills the value.
+ */
+ if (opline->opcode == ZEND_CASE) {
+ zval old_val;
+ old_val = *val;
+ zval_copy_ctor(val);
+ update_op1_const(op_array, opline, val TSRMLS_CC);
+ *val = old_val;
+ } else if (opline->opcode == ZEND_FREE) {
+ MAKE_NOP(opline);
+ break;
+ } else {
+ update_op1_const(op_array, opline, val TSRMLS_CC);
+ val = NULL;
+ break;
+ }
}
if (ZEND_OP2_TYPE(opline) == IS_TMP_VAR &&
ZEND_OP2(opline).var == var) {
update_op2_const(op_array, opline, val TSRMLS_CC);
- /* TMP_VAR my be used only once */
+ /* TMP_VAR may be used only once */
+ val = NULL;
break;
}
opline++;
}
+ if (val) {
+ zval_dtor(val);
+ }
}
#include "Optimizer/nop_removal.c"