Skip to content

Commit e721a42

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fixed reference counting inference
2 parents e002556 + c0bb238 commit e721a42

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3345,6 +3345,20 @@ static zend_always_inline int _zend_update_type_info(
33453345
if (opline->opcode == ZEND_FETCH_DIM_IS && (t1 & MAY_BE_STRING)) {
33463346
tmp |= MAY_BE_NULL;
33473347
}
3348+
if ((tmp & (MAY_BE_RC1|MAY_BE_RCN)) == MAY_BE_RCN && opline->result_type == IS_TMP_VAR) {
3349+
/* refcount may be indirectly decremented. Make an exception if the result is used in the next instruction */
3350+
if (!ssa_opcodes) {
3351+
if (ssa->vars[ssa_op->result_def].use_chain < 0
3352+
|| opline + 1 != op_array->opcodes + ssa->vars[ssa_op->result_def].use_chain) {
3353+
tmp |= MAY_BE_RC1;
3354+
}
3355+
} else {
3356+
if (ssa->vars[ssa_op->result_def].use_chain < 0
3357+
|| opline + 1 != ssa_opcodes[ssa->vars[ssa_op->result_def].use_chain]) {
3358+
tmp |= MAY_BE_RC1;
3359+
}
3360+
}
3361+
}
33483362
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
33493363
break;
33503364
case ZEND_FETCH_THIS:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
JIT FETCH_DIM_R: 013
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
function foo() {
11+
$y = 0; $tokens = [];
12+
for($cnt = 0; $cnt < 6; $cnt++) {
13+
$tokens[$y] > $tokens[$y][] = $y;
14+
}
15+
}
16+
@foo();
17+
?>
18+
DONE
19+
--EXPECT--
20+
DONE

0 commit comments

Comments
 (0)