diff --git a/ext/opcache/jit/zend_jit_ir.c b/ext/opcache/jit/zend_jit_ir.c index 7c35481e1a4..4f1d81c4d07 100644 --- a/ext/opcache/jit/zend_jit_ir.c +++ b/ext/opcache/jit/zend_jit_ir.c @@ -9878,7 +9878,10 @@ static int zend_jit_do_fcall(zend_jit_ctx *jit, const zend_op *opline, const zen } if (ZEND_OBSERVER_ENABLED) { - if (GCC_GLOBAL_REGS) { + if (trace && (trace->op != ZEND_JIT_TRACE_END || trace->stop != ZEND_JIT_TRACE_STOP_INTERPRETER)) { + ZEND_ASSERT(trace[1].op == ZEND_JIT_TRACE_VM || trace[1].op == ZEND_JIT_TRACE_END); + jit_SET_EX_OPLINE(jit, trace[1].opline); + } else if (GCC_GLOBAL_REGS) { // EX(opline) = opline ir_STORE(jit_EX(opline), jit_IP(jit)); } diff --git a/ext/opcache/tests/jit/gh13772.phpt b/ext/opcache/tests/jit/gh13772.phpt new file mode 100644 index 00000000000..97fa6536e0c --- /dev/null +++ b/ext/opcache/tests/jit/gh13772.phpt @@ -0,0 +1,26 @@ +--TEST-- +EX(opline) is correctly set for nested JIT user code calls +--EXTENSIONS-- +opcache +zend_test +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +zend_test.observer.enabled=1 +zend_test.observer.observe_all=1 +zend_test.observer.show_output=0 +--FILE-- + +--EXPECT-- +int(61) + diff --git a/ext/zend_test/observer.c b/ext/zend_test/observer.c index 9bcbd8ee6d6..37bbdbbd3c8 100644 --- a/ext/zend_test/observer.c +++ b/ext/zend_test/observer.c @@ -67,8 +67,16 @@ static void observer_show_opcode(zend_execute_data *execute_data) php_printf("%*s\n", 2 * ZT_G(observer_nesting_depth), "", zend_get_opcode_name(EX(opline)->opcode)); } +static inline void assert_observer_opline(zend_execute_data *execute_data) { + ZEND_ASSERT(!ZEND_USER_CODE(EX(func)->type) || + (EX(opline) >= EX(func)->op_array.opcodes && EX(opline) < EX(func)->op_array.opcodes + EX(func)->op_array.last) || + (EX(opline) >= EG(exception_op) && EX(opline) < EG(exception_op) + 3)); +} + static void observer_begin(zend_execute_data *execute_data) { + assert_observer_opline(execute_data); + if (!ZT_G(observer_show_output)) { return; } @@ -112,6 +120,8 @@ static void get_retval_info(zval *retval, smart_str *buf) static void observer_end(zend_execute_data *execute_data, zval *retval) { + assert_observer_opline(execute_data); + if (!ZT_G(observer_show_output)) { return; }