Skip to content

Commit 8862e23

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix reference contig inference
2 parents b36f25a + de358f8 commit 8862e23

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
@@ -2235,6 +2235,25 @@ static uint32_t zend_fetch_prop_type(const zend_script *script, zend_property_in
22352235
return zend_convert_type(script, prop_info->type, pce);
22362236
}
22372237

2238+
static bool result_may_be_separated(zend_ssa *ssa, zend_ssa_op *ssa_op)
2239+
{
2240+
int tmp_var = ssa_op->result_def;
2241+
2242+
if (ssa->vars[tmp_var].use_chain >= 0
2243+
&& !ssa->vars[tmp_var].phi_use_chain) {
2244+
zend_ssa_op *use_op = &ssa->ops[ssa->vars[tmp_var].use_chain];
2245+
2246+
/* TODO: analize instructions between ssa_op and use_op */
2247+
if (use_op == ssa_op + 1) {
2248+
if ((use_op->op1_use == tmp_var && use_op->op1_use_chain < 0)
2249+
|| (use_op->op2_use == tmp_var && use_op->op2_use_chain < 0)) {
2250+
return 0;
2251+
}
2252+
}
2253+
}
2254+
return 1;
2255+
}
2256+
22382257
static zend_always_inline int _zend_update_type_info(
22392258
const zend_op_array *op_array,
22402259
zend_ssa *ssa,
@@ -3340,11 +3359,11 @@ static zend_always_inline int _zend_update_type_info(
33403359
if (prop_info) {
33413360
/* FETCH_OBJ_R/IS for plain property increments reference counter,
33423361
so it can't be 1 */
3343-
if (ce && !ce->create_object) {
3362+
if (ce && !ce->create_object && !result_may_be_separated(ssa, ssa_op)) {
33443363
tmp &= ~MAY_BE_RC1;
33453364
}
33463365
} else {
3347-
if (ce && !ce->create_object && !ce->__get) {
3366+
if (ce && !ce->create_object && !ce->__get && !result_may_be_separated(ssa, ssa_op)) {
33483367
tmp &= ~MAY_BE_RC1;
33493368
}
33503369
}
@@ -3370,7 +3389,9 @@ static zend_always_inline int _zend_update_type_info(
33703389
if (opline->result_type == IS_VAR) {
33713390
tmp |= MAY_BE_REF | MAY_BE_INDIRECT;
33723391
} else {
3373-
tmp &= ~MAY_BE_RC1;
3392+
if (!result_may_be_separated(ssa, ssa_op)) {
3393+
tmp &= ~MAY_BE_RC1;
3394+
}
33743395
if (opline->opcode == ZEND_FETCH_STATIC_PROP_IS) {
33753396
tmp |= MAY_BE_UNDEF;
33763397
}
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)