From d7fc3ab07f3279ee8f5d6b5baad330aa090e62b3 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 1 Nov 2023 16:11:54 +0300 Subject: [PATCH] Fixed GH-12585: Assertion t->stack_map[t->exit_info[exit_point].stack_offset + var].type == 4 --- ext/opcache/jit/zend_jit_trace.c | 33 ++++++++++++++---------------- ext/opcache/tests/jit/gh12585.phpt | 30 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 ext/opcache/tests/jit/gh12585.phpt diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c index ee5170467c5..99cd1a8f196 100644 --- a/ext/opcache/jit/zend_jit_trace.c +++ b/ext/opcache/jit/zend_jit_trace.c @@ -2850,9 +2850,11 @@ static zend_jit_reg_var* zend_jit_trace_allocate_registers(zend_jit_trace_rec *t } if (ssa_op->op1_use >= 0 - && RA_HAS_IVAL(ssa_op->op1_use) - && !zend_ssa_is_no_val_use(opline, ssa_op, ssa_op->op1_use)) { - if (support_opline) { + && RA_HAS_IVAL(ssa_op->op1_use)) { + if (!support_opline) { + RA_IVAL_DEL(ssa_op->op1_use); + count--; + } else if (!zend_ssa_is_no_val_use(opline, ssa_op, ssa_op->op1_use)) { zend_jit_trace_use_var(idx, ssa_op->op1_use, ssa_op->op1_def, ssa_op->op1_use_chain, ra, ssa, ssa_opcodes, op_array, op_array_ssa); @@ -2876,41 +2878,36 @@ static zend_jit_reg_var* zend_jit_trace_allocate_registers(zend_jit_trace_rec *t RA_IVAL_FLAGS(ssa_op->op1_use) |= ZREG_LAST_USE; } } - } else { - RA_IVAL_DEL(ssa_op->op1_use); - count--; } } if (ssa_op->op2_use >= 0 && ssa_op->op2_use != ssa_op->op1_use - && RA_HAS_IVAL(ssa_op->op2_use) - && !zend_ssa_is_no_val_use(opline, ssa_op, ssa_op->op2_use)) { + && RA_HAS_IVAL(ssa_op->op2_use)) { /* Quick workaround to disable register allocation for unsupported operand */ // TODO: Find a general solution ??? - if (support_opline && opline->opcode != ZEND_FETCH_DIM_R) { + if (!support_opline || opline->opcode == ZEND_FETCH_DIM_R) { + RA_IVAL_DEL(ssa_op->op2_use); + count--; + } else if (!zend_ssa_is_no_val_use(opline, ssa_op, ssa_op->op2_use)) { zend_jit_trace_use_var(idx, ssa_op->op2_use, ssa_op->op2_def, ssa_op->op2_use_chain, ra, ssa, ssa_opcodes, op_array, op_array_ssa); if (opline->op2_type != IS_CV) { RA_IVAL_FLAGS(ssa_op->op2_use) |= ZREG_LAST_USE; } - } else { - RA_IVAL_DEL(ssa_op->op2_use); - count--; } } if (ssa_op->result_use >= 0 && ssa_op->result_use != ssa_op->op1_use && ssa_op->result_use != ssa_op->op2_use - && RA_HAS_IVAL(ssa_op->result_use) - && !zend_ssa_is_no_val_use(opline, ssa_op, ssa_op->result_use)) { - if (support_opline) { + && RA_HAS_IVAL(ssa_op->result_use)) { + if (!support_opline) { + RA_IVAL_DEL(ssa_op->result_use); + count--; + } else if (!zend_ssa_is_no_val_use(opline, ssa_op, ssa_op->result_use)) { zend_jit_trace_use_var(idx, ssa_op->result_use, ssa_op->result_def, ssa_op->res_use_chain, ra, ssa, ssa_opcodes, op_array, op_array_ssa); - } else { - RA_IVAL_DEL(ssa_op->result_use); - count--; } } diff --git a/ext/opcache/tests/jit/gh12585.phpt b/ext/opcache/tests/jit/gh12585.phpt new file mode 100644 index 00000000000..afbe20936e6 --- /dev/null +++ b/ext/opcache/tests/jit/gh12585.phpt @@ -0,0 +1,30 @@ +--TEST-- +GH-12585: Assertion t->stack_map[t->exit_info[exit_point].stack_offset + var].type == 4 +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.jit_hot_func=1 +opcache.jit_hot_loop=1 +opcache.jit_hot_return=1 +opcache.jit_hot_side_exit=1 +opcache.jit=1152 +--FILE-- + +DONE +--EXPECT-- +DONE