Skip to content

Commit 8a45323

Browse files
committed
Improve fix for bug #75687
Adding an (incorrect) UNDEF here may cause subsequent narrowing in other places. Instead, let's try to handle this edge-case once for all instructions...
1 parent f01d5fa commit 8a45323

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

ext/opcache/Optimizer/zend_inference.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,6 +2154,24 @@ static int zend_update_type_info(const zend_op_array *op_array,
21542154
t1 = OP1_INFO();
21552155
t2 = OP2_INFO();
21562156

2157+
/* If one of the operands cannot have any type, this means the operand derives from
2158+
* unreachable code. Propagate the empty result early, so that that the following
2159+
* code may assume that operands have at least one type. */
2160+
if (!(t1 & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_CLASS|MAY_BE_ERROR))
2161+
|| !(t2 & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_CLASS|MAY_BE_ERROR))) {
2162+
tmp = 0;
2163+
if (ssa_ops[i].result_def >= 0) {
2164+
UPDATE_SSA_TYPE(tmp, ssa_ops[i].result_def);
2165+
}
2166+
if (ssa_ops[i].op1_def >= 0) {
2167+
UPDATE_SSA_TYPE(tmp, ssa_ops[i].op1_def);
2168+
}
2169+
if (ssa_ops[i].op2_def >= 0) {
2170+
UPDATE_SSA_TYPE(tmp, ssa_ops[i].op2_def);
2171+
}
2172+
return 1;
2173+
}
2174+
21572175
switch (opline->opcode) {
21582176
case ZEND_ADD:
21592177
case ZEND_SUB:
@@ -3338,9 +3356,6 @@ int zend_infer_types_ex(const zend_op_array *op_array, const zend_script *script
33383356
/* Ignore the constraint (either ce instanceof constraint->ce or
33393357
* they are unrelated, as far as we can statically determine) */
33403358
}
3341-
} else if ((tmp & MAY_BE_ANY) == 0) {
3342-
/* FIXME: usage in unreachable block */
3343-
tmp |= MAY_BE_UNDEF;
33443359
}
33453360
}
33463361

0 commit comments

Comments
 (0)