Skip to content

Commit de358f8

Browse files
committed
Fix reference contig inference
Fixes oss-fuzz #43032
1 parent 87d9e02 commit de358f8

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

ext/opcache/Optimizer/zend_inference.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,25 @@ static uint32_t zend_fetch_prop_type(const zend_script *script, zend_property_in
21912191
return MAY_BE_ANY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF | MAY_BE_RC1 | MAY_BE_RCN;
21922192
}
21932193

2194+
static zend_bool result_may_be_separated(zend_ssa *ssa, zend_ssa_op *ssa_op)
2195+
{
2196+
int tmp_var = ssa_op->result_def;
2197+
2198+
if (ssa->vars[tmp_var].use_chain >= 0
2199+
&& !ssa->vars[tmp_var].phi_use_chain) {
2200+
zend_ssa_op *use_op = &ssa->ops[ssa->vars[tmp_var].use_chain];
2201+
2202+
/* TODO: analize instructions between ssa_op and use_op */
2203+
if (use_op == ssa_op + 1) {
2204+
if ((use_op->op1_use == tmp_var && use_op->op1_use_chain < 0)
2205+
|| (use_op->op2_use == tmp_var && use_op->op2_use_chain < 0)) {
2206+
return 0;
2207+
}
2208+
}
2209+
}
2210+
return 1;
2211+
}
2212+
21942213
static zend_always_inline int _zend_update_type_info(
21952214
const zend_op_array *op_array,
21962215
zend_ssa *ssa,
@@ -3307,11 +3326,11 @@ static zend_always_inline int _zend_update_type_info(
33073326
if (prop_info) {
33083327
/* FETCH_OBJ_R/IS for plain property increments reference counter,
33093328
so it can't be 1 */
3310-
if (ce && !ce->create_object) {
3329+
if (ce && !ce->create_object && !result_may_be_separated(ssa, ssa_op)) {
33113330
tmp &= ~MAY_BE_RC1;
33123331
}
33133332
} else {
3314-
if (ce && !ce->create_object && !ce->__get) {
3333+
if (ce && !ce->create_object && !ce->__get && !result_may_be_separated(ssa, ssa_op)) {
33153334
tmp &= ~MAY_BE_RC1;
33163335
}
33173336
}
@@ -3336,7 +3355,7 @@ static zend_always_inline int _zend_update_type_info(
33363355
zend_fetch_static_prop_info(script, op_array, ssa, opline), &ce);
33373356
if (opline->result_type != IS_TMP_VAR) {
33383357
tmp |= MAY_BE_REF | MAY_BE_INDIRECT;
3339-
} else {
3358+
} else if (!result_may_be_separated(ssa, ssa_op)) {
33403359
tmp &= ~MAY_BE_RC1;
33413360
}
33423361
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
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)