Skip to content

Commit a3c7adf

Browse files
committed
Free extra named args in jit
1 parent e1e7ae5 commit a3c7adf

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
@@ -8558,6 +8558,7 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
85588558
#endif
85598559
}
85608560

8561+
// TODO: This could be more precise by checking MAY_BE_ARRAY_KEY_STRING for unpacks.
85618562
bool may_have_named_args = 0;
85628563
if ((opline-1)->opcode == ZEND_SEND_UNPACK || (opline-1)->opcode == ZEND_SEND_ARRAY ||
85638564
opline->extended_value == ZEND_FCALL_HAS_NAMED_ARGS) {
@@ -8870,6 +8871,7 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
88708871
| mov ecx, dword [FP + offsetof(zend_execute_data, This.u2.num_args)] // reload
88718872
| jmp >1
88728873
|.code
8874+
// TODO: Emit ZEND_CALL_MAY_HAVE_UNDEF check for named args.
88738875
if (!may_have_named_args &&
88748876
(!func || (func->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) {
88758877
if (!func) {
@@ -9020,6 +9022,17 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
90209022
| mov FCARG1a, RX
90219023
| EXT_CALL zend_jit_vm_stack_free_args_helper, r0
90229024
}
9025+
if (may_have_named_args) {
9026+
| test byte [RX + offsetof(zend_execute_data, This.u1.type_info) + 3], (ZEND_CALL_HAS_EXTRA_NAMED_PARAMS >> 24)
9027+
| jnz >1
9028+
|1:
9029+
|.cold_code
9030+
| mov FCARG1a, aword [RX + offsetof(zend_execute_data, extra_named_params)]
9031+
| EXT_CALL zend_array_destroy, r0
9032+
| jmp >2
9033+
|.code
9034+
|2:
9035+
}
90239036

90249037
|8:
90259038
if (opline->opcode == ZEND_DO_FCALL) {

0 commit comments

Comments
 (0)