Skip to content

Commit 43222b5

Browse files
committed
Implement frameless icall arity completion
1 parent 32d9e13 commit 43222b5

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

Zend/zend_compile.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4563,32 +4563,36 @@ static zend_result zend_compile_frameless_icall(znode *result, zend_ast_list *ar
45634563
}
45644564

45654565
while (frameless_function_info->handler) {
4566-
if (frameless_function_info->num_args == args->children) {
4567-
uint32_t offset = find_frameless_function_offset(args->children, frameless_function_info->handler);
4566+
if (frameless_function_info->num_args >= args->children
4567+
&& fbc->common.required_num_args <= args->children) {
4568+
uint32_t num_args = frameless_function_info->num_args;
4569+
uint32_t offset = find_frameless_function_offset(num_args, frameless_function_info->handler);
45684570
if (offset == (uint32_t)-1) {
45694571
continue;
45704572
}
4571-
znode arg1, arg2, arg3;
4572-
if (args->children >= 1) {
4573-
zend_compile_expr(&arg1, args->child[0]);
4574-
}
4575-
if (args->children >= 2) {
4576-
zend_compile_expr(&arg2, args->child[1]);
4577-
}
4578-
if (args->children >= 3) {
4579-
zend_compile_expr(&arg3, args->child[2]);
4573+
znode arg_zvs[3];
4574+
for (uint32_t i = 0; i < num_args; i++) {
4575+
if (i < args->children) {
4576+
zend_compile_expr(&arg_zvs[i], args->child[i]);
4577+
} else {
4578+
zend_internal_arg_info *arg_info = (zend_internal_arg_info *)&fbc->common.arg_info[i];
4579+
arg_zvs[i].op_type = IS_CONST;
4580+
if (zend_get_default_from_internal_arg_info(&arg_zvs[i].u.constant, arg_info) == FAILURE) {
4581+
ZEND_UNREACHABLE();
4582+
}
4583+
}
45804584
}
4581-
uint8_t opcode = ZEND_FRAMELESS_ICALL_0 + args->children;
4585+
uint8_t opcode = ZEND_FRAMELESS_ICALL_0 + num_args;
45824586
zend_op *opline = zend_emit_op_tmp(result, opcode, NULL, NULL);
45834587
opline->extended_value = offset;
4584-
if (args->children >= 1) {
4585-
SET_NODE(opline->op1, &arg1);
4588+
if (num_args >= 1) {
4589+
SET_NODE(opline->op1, &arg_zvs[0]);
45864590
}
4587-
if (args->children >= 2) {
4588-
SET_NODE(opline->op2, &arg2);
4591+
if (num_args >= 2) {
4592+
SET_NODE(opline->op2, &arg_zvs[1]);
45894593
}
4590-
if (args->children >= 3) {
4591-
zend_emit_op_data(&arg3);
4594+
if (num_args >= 3) {
4595+
zend_emit_op_data(&arg_zvs[2]);
45924596
}
45934597
return SUCCESS;
45944598
}

0 commit comments

Comments
 (0)