Skip to content

Commit 3079a72

Browse files
committed
JIT: Resolve escape_if_undef orig_handler via jit->current_op_array
zend_jit_escape_if_undef received an op_array pointer captured at parent-trace compile time. That pointer can go stale by the time a side trace compiles for the exit. Drop the parameter and read jit->current_op_array instead; zend_jit_trace_start sets it for trace compilation, and zend_jit_trace_exit_to_vm now seeds it from exit_info->op_array so the deoptimizer path has it too. Closes GH-21710
1 parent 05afc37 commit 3079a72

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

ext/opcache/jit/zend_jit_ir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8068,7 +8068,7 @@ static int zend_jit_defined(zend_jit_ctx *jit, const zend_op *opline, uint8_t sm
80688068
return 1;
80698069
}
80708070

8071-
static int zend_jit_escape_if_undef(zend_jit_ctx *jit, int var, uint32_t flags, const zend_op *opline, const zend_op_array *op_array, int8_t reg)
8071+
static int zend_jit_escape_if_undef(zend_jit_ctx *jit, int var, uint32_t flags, const zend_op *opline, int8_t reg)
80728072
{
80738073
zend_jit_addr reg_addr = ZEND_ADDR_REF_ZVAL(zend_jit_deopt_rload(jit, IR_ADDR, reg));
80748074
ir_ref if_def = ir_IF(jit_Z_TYPE(jit, reg_addr));
@@ -8094,7 +8094,7 @@ static int zend_jit_escape_if_undef(zend_jit_ctx *jit, int var, uint32_t flags,
80948094

80958095
/* We can't use trace_escape() because opcode handler may be overridden by JIT */
80968096
zend_jit_op_array_trace_extension *jit_extension =
8097-
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
8097+
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(jit->current_op_array);
80988098
size_t offset = jit_extension->offset;
80998099
ir_ref ref = ir_CONST_FC_FUNC(ZEND_OP_TRACE_INFO((opline - 1), offset)->orig_handler);
81008100
if (GCC_GLOBAL_REGS) {

ext/opcache/jit/zend_jit_trace.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3606,7 +3606,7 @@ static int zend_jit_trace_deoptimization(
36063606

36073607
ZEND_ASSERT(STACK_FLAGS(parent_stack, check2) == ZREG_ZVAL_COPY);
36083608
ZEND_ASSERT(reg != ZREG_NONE);
3609-
if (!zend_jit_escape_if_undef(jit, check2, flags, opline, exit_info->op_array, reg)) {
3609+
if (!zend_jit_escape_if_undef(jit, check2, flags, opline, reg)) {
36103610
return 0;
36113611
}
36123612
if (!zend_jit_restore_zval(jit, EX_NUM_TO_VAR(check2), reg)) {
@@ -7377,6 +7377,8 @@ static const void *zend_jit_trace_exit_to_vm(uint32_t trace_num, uint32_t exit_n
73777377
zend_jit_traces[trace_num].stack_map + zend_jit_traces[trace_num].exit_info[exit_num].stack_offset :
73787378
NULL;
73797379

7380+
ctx.current_op_array = zend_jit_traces[trace_num].exit_info[exit_num].op_array;
7381+
73807382
if (!zend_jit_trace_deoptimization(&ctx,
73817383
&zend_jit_traces[trace_num].exit_info[exit_num],
73827384
stack, stack_size, NULL, NULL,

0 commit comments

Comments
 (0)