Skip to content

Commit df4c276

Browse files
committed
Check opcode rather than result_type for R/IS type inference
We may sometimes create FETCH_*_R opcodes with VAR type (e.g. if a FUNC_ARG opcode is converted to BP_VAR_R fetch kind). Make sure we don't infer overly conservative types in that case.
1 parent 3f12d26 commit df4c276

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3368,7 +3368,8 @@ static zend_always_inline zend_result _zend_update_type_info(
33683368
tmp = zend_array_element_type(
33693369
opline->opcode != ZEND_FETCH_LIST_R ? t1 : ((t1 & ~MAY_BE_STRING) | MAY_BE_NULL),
33703370
opline->op1_type,
3371-
opline->result_type == IS_VAR,
3371+
opline->opcode != ZEND_FETCH_DIM_R && opline->opcode != ZEND_FETCH_DIM_IS
3372+
&& opline->opcode != ZEND_FETCH_LIST_R,
33723373
opline->op2_type == IS_UNUSED);
33733374
if (opline->opcode == ZEND_FETCH_DIM_IS && (t1 & MAY_BE_STRING)) {
33743375
tmp |= MAY_BE_NULL;
@@ -3409,7 +3410,7 @@ static zend_always_inline zend_result _zend_update_type_info(
34093410
if (opline->op1_type == IS_UNUSED || (t1 & MAY_BE_OBJECT)) {
34103411
zend_property_info *prop_info = zend_fetch_prop_info(op_array, ssa, opline, ssa_op);
34113412
tmp |= zend_fetch_prop_type(script, prop_info, &ce);
3412-
if (opline->result_type == IS_VAR) {
3413+
if (opline->opcode != ZEND_FETCH_OBJ_R && opline->opcode != ZEND_FETCH_OBJ_IS) {
34133414
tmp |= MAY_BE_REF | MAY_BE_INDIRECT;
34143415
ce = NULL;
34153416
} else if (!(opline->op1_type & (IS_VAR|IS_TMP_VAR)) || !(t1 & MAY_BE_RC1)) {
@@ -3451,7 +3452,8 @@ static zend_always_inline zend_result _zend_update_type_info(
34513452
case ZEND_FETCH_STATIC_PROP_FUNC_ARG:
34523453
tmp = zend_fetch_prop_type(script,
34533454
zend_fetch_static_prop_info(script, op_array, ssa, opline), &ce);
3454-
if (opline->result_type == IS_VAR) {
3455+
if (opline->opcode != ZEND_FETCH_STATIC_PROP_R
3456+
&& opline->opcode != ZEND_FETCH_STATIC_PROP_IS) {
34553457
tmp |= MAY_BE_REF | MAY_BE_INDIRECT;
34563458
} else {
34573459
if (!result_may_be_separated(ssa, ssa_op)) {

0 commit comments

Comments
 (0)