Skip to content

Commit 66271df

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Checj type guards before loading values into CPU registers Avoid register allocation for ASSIGN into aliased variable (it might be indirectly changed into IS_REFERENCE)
2 parents 35f1b0b + 20cbb23 commit 66271df

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,15 @@ static zend_lifetime_interval** zend_jit_trace_allocate_registers(zend_jit_trace
22112211

22122212
support_opline =
22132213
zend_jit_opline_supports_reg(op_array, ssa, opline, ssa_op, p);
2214+
2215+
if (support_opline
2216+
&& opline->opcode == ZEND_ASSIGN
2217+
&& opline->op1_type == IS_CV
2218+
&& zend_jit_var_may_alias(op_array, op_array_ssa, EX_VAR_TO_NUM(opline->op1.var)) != NO_ALIAS) {
2219+
/* avoid register allocation in case of possiblity of indirect modification*/
2220+
support_opline = 0;
2221+
}
2222+
22142223
if (ssa_op->op1_use >= 0
22152224
&& start[ssa_op->op1_use] >= 0
22162225
&& !zend_ssa_is_no_val_use(opline, ssa_op, ssa_op->op1_use)) {
@@ -3370,6 +3379,18 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
33703379
if (ra[i]
33713380
&& (ra[i]->flags & ZREG_LOAD) != 0
33723381
&& ra[i]->reg != stack[i].reg) {
3382+
3383+
if ((ssa->var_info[i].type & MAY_BE_GUARD) != 0) {
3384+
uint8_t op_type;
3385+
3386+
ssa->var_info[i].type &= ~MAY_BE_GUARD;
3387+
op_type = concrete_type(ssa->var_info[i].type);
3388+
if (!zend_jit_type_guard(&dasm_state, opline, i, op_type)) {
3389+
goto jit_failure;
3390+
}
3391+
SET_STACK_TYPE(stack, i, op_type, 1);
3392+
}
3393+
33733394
SET_STACK_REG_EX(stack, i, ra[i]->reg, ZREG_LOAD);
33743395
if (!zend_jit_load_var(&dasm_state, ssa->var_info[i].type, i, ra[i]->reg)) {
33753396
goto jit_failure;

0 commit comments

Comments
 (0)