Skip to content

Commit 5cae6b9

Browse files
committed
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.
1 parent 8c3d33a commit 5cae6b9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Zend/tests/post_inc_without_use.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
POST_INC without use during DFA optimization
3+
--FILE--
4+
<?php
5+
6+
function test($n) {
7+
for ($i = 0; $i < $n; !$i++) {}
8+
}
9+
10+
?>
11+
===DONE===
12+
--EXPECT--
13+
===DONE===

ext/opcache/Optimizer/dfa_pass.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
13881388
&& (ssa->var_info[result_var].type & ((MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_DOUBLE))) == 0) {
13891389
int use = ssa->vars[result_var].use_chain;
13901390

1391-
if (op_array->opcodes[use].opcode == ZEND_IS_SMALLER
1391+
if (use >= 0 && op_array->opcodes[use].opcode == ZEND_IS_SMALLER
13921392
&& ssa->ops[use].op1_use == result_var
13931393
&& zend_dfa_try_to_replace_result(op_array, ssa, op_1, v)) {
13941394
opline->opcode = ZEND_PRE_INC;
@@ -1402,7 +1402,7 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
14021402
&& (ssa->var_info[result_var].type & ((MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_DOUBLE))) == 0) {
14031403
int use = ssa->vars[result_var].use_chain;
14041404

1405-
if (op_array->opcodes[use].opcode == ZEND_IS_SMALLER
1405+
if (use >= 0 && op_array->opcodes[use].opcode == ZEND_IS_SMALLER
14061406
&& ssa->ops[use].op2_use == result_var
14071407
&& zend_dfa_try_to_replace_result(op_array, ssa, op_1, v)) {
14081408
opline->opcode = ZEND_PRE_DEC;

0 commit comments

Comments
 (0)