Skip to content

Commit cbe485d

Browse files
committed
Make PRE_INC/PRE_DEC type inference more accurate
The return value can never be a reference, even if the variable is a reference. While here, also exclude the resource and array types which throw a TypeError since PHP 8.0.
1 parent b58d745 commit cbe485d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,9 +2631,6 @@ static zend_always_inline int _zend_update_type_info(
26312631
case ZEND_PRE_INC:
26322632
case ZEND_PRE_DEC:
26332633
tmp = 0;
2634-
if (t1 & MAY_BE_REF) {
2635-
tmp |= MAY_BE_REF;
2636-
}
26372634
if (t1 & (MAY_BE_RC1|MAY_BE_RCN)) {
26382635
tmp |= MAY_BE_RC1;
26392636
if (ssa_op->result_def >= 0) {
@@ -2670,14 +2667,17 @@ static zend_always_inline int _zend_update_type_info(
26702667
if (t1 & MAY_BE_STRING) {
26712668
tmp |= MAY_BE_STRING | MAY_BE_LONG | MAY_BE_DOUBLE;
26722669
}
2673-
tmp |= t1 & (MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_RESOURCE | MAY_BE_ARRAY | MAY_BE_OBJECT | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF | MAY_BE_ARRAY_KEY_ANY);
2674-
}
2675-
if (ssa_op->op1_def >= 0) {
2676-
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
2670+
tmp |= t1 & (MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_OBJECT);
26772671
}
26782672
if (ssa_op->result_def >= 0) {
26792673
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
26802674
}
2675+
if (ssa_op->op1_def >= 0) {
2676+
if (t1 & MAY_BE_REF) {
2677+
tmp |= MAY_BE_REF;
2678+
}
2679+
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
2680+
}
26812681
break;
26822682
case ZEND_POST_INC:
26832683
case ZEND_POST_DEC:

0 commit comments

Comments
 (0)