Skip to content

Commit 5355cf3

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Check that POST_INC/DEC has use in DFA optimization
2 parents 6381a16 + f6daf83 commit 5355cf3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Zend/Optimizer/dfa_pass.c

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

1438-
if (op_array->opcodes[use].opcode == ZEND_IS_SMALLER
1438+
if (use >= 0 && op_array->opcodes[use].opcode == ZEND_IS_SMALLER
14391439
&& ssa->ops[use].op1_use == result_var
14401440
&& zend_dfa_try_to_replace_result(op_array, ssa, op_1, v)) {
14411441
opline->opcode = ZEND_PRE_INC;
@@ -1449,7 +1449,7 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
14491449
&& (ssa->var_info[result_var].type & ((MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_DOUBLE))) == 0) {
14501450
int use = ssa->vars[result_var].use_chain;
14511451

1452-
if (op_array->opcodes[use].opcode == ZEND_IS_SMALLER
1452+
if (use >= 0 && op_array->opcodes[use].opcode == ZEND_IS_SMALLER
14531453
&& ssa->ops[use].op2_use == result_var
14541454
&& zend_dfa_try_to_replace_result(op_array, ssa, op_1, v)) {
14551455
opline->opcode = ZEND_PRE_DEC;

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

0 commit comments

Comments
 (0)