Skip to content

Commit 1bb7ee3

Browse files
committed
Fix ASSIGN_DIM result inference with typed refs
Same issue as with ASSIGN. Also make the handling for ASSIGN more precise, we can only have conversions between scalar values.
1 parent cdc05eb commit 1bb7ee3

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Zend/tests/assign_typed_ref_result.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ function test() {
1111
$ref =& $obj->prop;
1212
var_dump($ref = 0);
1313
}
14+
function test2() {
15+
$obj = new Test;
16+
$ary = [];
17+
$ary[0] =& $obj->prop;
18+
var_dump($ary[0] = 0);
19+
}
1420
test();
21+
test2();
1522

1623
?>
1724
--EXPECT--
1825
string(1) "0"
26+
string(1) "0"

ext/opcache/Optimizer/zend_inference.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,6 +2757,10 @@ static zend_always_inline int _zend_update_type_info(
27572757
if (OP1_DATA_INFO() & MAY_BE_UNDEF) {
27582758
tmp |= MAY_BE_NULL;
27592759
}
2760+
if (t1 & MAY_BE_ARRAY_OF_REF) {
2761+
/* A scalar type conversion may occur when assigning to a typed reference. */
2762+
tmp |= MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING;
2763+
}
27602764
}
27612765
if (t1 & MAY_BE_OBJECT) {
27622766
tmp |= MAY_BE_REF;
@@ -2866,9 +2870,9 @@ static zend_always_inline int _zend_update_type_info(
28662870
}
28672871
if (ssa_op->result_def >= 0) {
28682872
if (tmp & MAY_BE_REF) {
2869-
/* Assignment to typed reference may change type.
2870-
* Be conservative and don't assume anything. */
2871-
tmp = MAY_BE_RC1|MAY_BE_RCN|MAY_BE_ANY|MAY_BE_ARRAY_KEY_ANY|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF;
2873+
/* A scalar type conversion may occur when assigning to a typed reference. */
2874+
tmp &= ~MAY_BE_REF;
2875+
tmp |= MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING|MAY_BE_RC1|MAY_BE_RCN;
28722876
}
28732877
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
28742878
COPY_SSA_OBJ_TYPE(ssa_op->op2_use, ssa_op->result_def);

0 commit comments

Comments
 (0)