Skip to content

Commit 3319f17

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix reference contig inference
2 parents 693c880 + 8862e23 commit 3319f17

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,25 @@ static uint32_t zend_fetch_prop_type(const zend_script *script, zend_property_in
22582258
return zend_convert_type(script, prop_info->type, pce);
22592259
}
22602260

2261+
static bool result_may_be_separated(zend_ssa *ssa, zend_ssa_op *ssa_op)
2262+
{
2263+
int tmp_var = ssa_op->result_def;
2264+
2265+
if (ssa->vars[tmp_var].use_chain >= 0
2266+
&& !ssa->vars[tmp_var].phi_use_chain) {
2267+
zend_ssa_op *use_op = &ssa->ops[ssa->vars[tmp_var].use_chain];
2268+
2269+
/* TODO: analize instructions between ssa_op and use_op */
2270+
if (use_op == ssa_op + 1) {
2271+
if ((use_op->op1_use == tmp_var && use_op->op1_use_chain < 0)
2272+
|| (use_op->op2_use == tmp_var && use_op->op2_use_chain < 0)) {
2273+
return 0;
2274+
}
2275+
}
2276+
}
2277+
return 1;
2278+
}
2279+
22612280
static zend_always_inline zend_result _zend_update_type_info(
22622281
const zend_op_array *op_array,
22632282
zend_ssa *ssa,
@@ -3366,11 +3385,11 @@ static zend_always_inline zend_result _zend_update_type_info(
33663385
if (prop_info) {
33673386
/* FETCH_OBJ_R/IS for plain property increments reference counter,
33683387
so it can't be 1 */
3369-
if (ce && !ce->create_object) {
3388+
if (ce && !ce->create_object && !result_may_be_separated(ssa, ssa_op)) {
33703389
tmp &= ~MAY_BE_RC1;
33713390
}
33723391
} else {
3373-
if (ce && !ce->create_object && !ce->__get) {
3392+
if (ce && !ce->create_object && !ce->__get && !result_may_be_separated(ssa, ssa_op)) {
33743393
tmp &= ~MAY_BE_RC1;
33753394
}
33763395
}
@@ -3396,7 +3415,9 @@ static zend_always_inline zend_result _zend_update_type_info(
33963415
if (opline->result_type == IS_VAR) {
33973416
tmp |= MAY_BE_REF | MAY_BE_INDIRECT;
33983417
} else {
3399-
tmp &= ~MAY_BE_RC1;
3418+
if (!result_may_be_separated(ssa, ssa_op)) {
3419+
tmp &= ~MAY_BE_RC1;
3420+
}
34003421
if (opline->opcode == ZEND_FETCH_STATIC_PROP_IS) {
34013422
tmp |= MAY_BE_UNDEF;
34023423
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
JIT: FETCH_OBJ 009
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 test() {
11+
for ($i = 0; $i < 10; $i++) {
12+
$obj = new stdClass;
13+
$obj->x[0] = null;
14+
$obj->x > $obj->x[0] = null;
15+
}
16+
}
17+
test();
18+
?>
19+
DONE
20+
--EXPECT--
21+
DONE

0 commit comments

Comments
 (0)