From f3d8ac1d954d4104eebb2ac2d94c46f23e2ab5da Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 13 Feb 2020 15:16:23 +0100 Subject: [PATCH] Fix JIT trait type errors We need to load EX->func here rather than use a hardcoded op_array, as it may be copied with adjusted scope for traits. --- Zend/tests/trait_type_errors.phpt | 43 +++++++++++++++++++++++++++++++ ext/opcache/jit/zend_jit_x86.dasc | 6 ++--- 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 Zend/tests/trait_type_errors.phpt diff --git a/Zend/tests/trait_type_errors.phpt b/Zend/tests/trait_type_errors.phpt new file mode 100644 index 0000000000..50f5d619ad --- /dev/null +++ b/Zend/tests/trait_type_errors.phpt @@ -0,0 +1,43 @@ +--TEST-- +Type errors for methods from traits should refer to using class +--FILE-- +test1("foo"); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} +try { + $c->test2("foo"); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} +try { + $c->test3("foo"); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECTF-- +Return value of C::test1() must be of the type int, string returned +Argument 1 passed to C::test2() must be of the type int, string given, called in %s on line %d +Argument 1 passed to C::test3() must be of the type int, string given, called in %s on line %d diff --git a/ext/opcache/jit/zend_jit_x86.dasc b/ext/opcache/jit/zend_jit_x86.dasc index 75c9b510fe..3b6e3b26f5 100644 --- a/ext/opcache/jit/zend_jit_x86.dasc +++ b/ext/opcache/jit/zend_jit_x86.dasc @@ -8640,7 +8640,7 @@ static int zend_jit_recv(dasm_State **Dst, const zend_op *opline, const zend_op_ | mov FCARG1a, r0 | mov r0, EX->run_time_cache | add r0, opline->extended_value - | LOAD_ADDR FCARG2a, (ptrdiff_t)op_array + | mov FCARG2a, EX->func |.if X64WIN | mov CARG3, arg_num | LOAD_ADDR CARG4, (ptrdiff_t)arg_info @@ -8784,7 +8784,7 @@ static int zend_jit_recv_init(dasm_State **Dst, const zend_op *opline, const zen | mov FCARG1a, r0 | mov r0, EX->run_time_cache | lea r0, [r0 + opline->extended_value] - | LOAD_ADDR FCARG2a, (ptrdiff_t)op_array + | mov FCARG2a, EX->func |.if X64WIN | mov CARG3, arg_num | LOAD_ADDR CARG4, (ptrdiff_t)arg_info @@ -9345,7 +9345,7 @@ static zend_bool zend_jit_verify_return_type(dasm_State **Dst, const zend_op *op | mov FCARG1a, r0 | mov r0, EX->run_time_cache | add r0, opline->op2.num - | LOAD_ADDR FCARG2a, (ptrdiff_t)op_array + | mov FCARG2a, EX->func |.if X64 | LOAD_ADDR CARG3, (ptrdiff_t)arg_info | mov CARG4, r0 -- 2.49.0