From 5cae6b9b0dffb7f8ecc6c8da94d4110334071774 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 9 Sep 2021 15:48:51 +0200 Subject: [PATCH] Check that POST_INC/DEC has use in DFA optimization We'd have usually converted it into a PRE_INC if there is no use, but that's not guaranteed. If there is no use at this point, make sure we don't try to use the sentinel value. --- Zend/tests/post_inc_without_use.phpt | 13 +++++++++++++ ext/opcache/Optimizer/dfa_pass.c | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 Zend/tests/post_inc_without_use.phpt diff --git a/Zend/tests/post_inc_without_use.phpt b/Zend/tests/post_inc_without_use.phpt new file mode 100644 index 00000000000..9c31e02baf1 --- /dev/null +++ b/Zend/tests/post_inc_without_use.phpt @@ -0,0 +1,13 @@ +--TEST-- +POST_INC without use during DFA optimization +--FILE-- + +===DONE=== +--EXPECT-- +===DONE=== diff --git a/ext/opcache/Optimizer/dfa_pass.c b/ext/opcache/Optimizer/dfa_pass.c index 0ac6c563d08..6ee9cdde1ed 100644 --- a/ext/opcache/Optimizer/dfa_pass.c +++ b/ext/opcache/Optimizer/dfa_pass.c @@ -1388,7 +1388,7 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx && (ssa->var_info[result_var].type & ((MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_DOUBLE))) == 0) { int use = ssa->vars[result_var].use_chain; - if (op_array->opcodes[use].opcode == ZEND_IS_SMALLER + if (use >= 0 && op_array->opcodes[use].opcode == ZEND_IS_SMALLER && ssa->ops[use].op1_use == result_var && zend_dfa_try_to_replace_result(op_array, ssa, op_1, v)) { opline->opcode = ZEND_PRE_INC; @@ -1402,7 +1402,7 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx && (ssa->var_info[result_var].type & ((MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_DOUBLE))) == 0) { int use = ssa->vars[result_var].use_chain; - if (op_array->opcodes[use].opcode == ZEND_IS_SMALLER + if (use >= 0 && op_array->opcodes[use].opcode == ZEND_IS_SMALLER && ssa->ops[use].op2_use == result_var && zend_dfa_try_to_replace_result(op_array, ssa, op_1, v)) { opline->opcode = ZEND_PRE_DEC;