Skip to content

Commit 980bb81

Browse files
committed
Free extra named args in jit
1 parent afc46ab commit 980bb81

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Zend/tests/named_params/internal.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var_dump(array_slice(length: 2, offset: 2, arg: [1, 2, 3, 4, 5]));
88

99
var_dump(array_slice(arg: ['a' => 0, 'b' => 1], offset: 1, preserve_keys: true));
1010
var_dump(array_slice(['a' => 0, 'b' => 1], preserve_keys: true, offset: 1));
11+
var_dump(str_pad("foo", 6, pad_type: STR_PAD_LEFT));
1112

1213
// Named params work with specialized functions.
1314
var_dump(strlen(string: 'foo'));
@@ -34,4 +35,5 @@ array(1) {
3435
["b"]=>
3536
int(1)
3637
}
38+
string(6) " foo"
3739
int(3)

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_leave_top_func_helper(uint32_t ca
9292
}
9393
zend_vm_stack_free_extra_args_ex(call_info, execute_data);
9494
}
95+
if (UNEXPECTED(call_info & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)) {
96+
zend_array_destroy(EX(extra_named_params));
97+
}
9598
if (UNEXPECTED(call_info & ZEND_CALL_CLOSURE)) {
9699
OBJ_RELEASE(ZEND_CLOSURE_OBJECT(EX(func)));
97100
}

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8567,6 +8567,7 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
85678567
#endif
85688568
}
85698569

8570+
// TODO: This could be more precise by checking MAY_BE_ARRAY_KEY_STRING for unpacks.
85708571
bool may_have_named_args = 0;
85718572
if ((opline-1)->opcode == ZEND_SEND_UNPACK || (opline-1)->opcode == ZEND_SEND_ARRAY ||
85728573
opline->extended_value == ZEND_FCALL_HAS_NAMED_ARGS) {
@@ -8879,6 +8880,7 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
88798880
| mov ecx, dword [FP + offsetof(zend_execute_data, This.u2.num_args)] // reload
88808881
| jmp >1
88818882
|.code
8883+
// TODO: Emit ZEND_CALL_MAY_HAVE_UNDEF check for named args.
88828884
if (!may_have_named_args &&
88838885
(!func || (func->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) {
88848886
if (!func) {
@@ -9029,6 +9031,17 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
90299031
| mov FCARG1a, RX
90309032
| EXT_CALL zend_jit_vm_stack_free_args_helper, r0
90319033
}
9034+
if (may_have_named_args) {
9035+
| test byte [RX + offsetof(zend_execute_data, This.u1.type_info) + 3], (ZEND_CALL_HAS_EXTRA_NAMED_PARAMS >> 24)
9036+
| jnz >1
9037+
|1:
9038+
|.cold_code
9039+
| mov FCARG1a, aword [RX + offsetof(zend_execute_data, extra_named_params)]
9040+
| EXT_CALL zend_array_destroy, r0
9041+
| jmp >2
9042+
|.code
9043+
|2:
9044+
}
90329045

90339046
|8:
90349047
if (opline->opcode == ZEND_DO_FCALL) {

0 commit comments

Comments
 (0)