diff --git a/src/analyze.cpp b/src/analyze.cpp index f1f294fdd..25065e9f8 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -898,7 +898,7 @@ static TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) { return fn_type; } -void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node) { +void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc) { assert(proto_node->type == NodeTypeFnProto); AstNodeFnProto *fn_proto = &proto_node->data.fn_proto; @@ -906,7 +906,7 @@ void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node) { fn_type_id->is_naked = fn_proto->is_nakedcc; fn_type_id->is_cold = fn_proto->is_coldcc; fn_type_id->param_count = fn_proto->params.length; - fn_type_id->param_info = allocate_nonzero(fn_type_id->param_count); + fn_type_id->param_info = allocate_nonzero(param_count_alloc); fn_type_id->next_param_index = 0; fn_type_id->is_var_args = fn_proto->is_var_args; } @@ -916,7 +916,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c AstNodeFnProto *fn_proto = &proto_node->data.fn_proto; FnTypeId fn_type_id = {0}; - init_fn_type_id(&fn_type_id, proto_node); + init_fn_type_id(&fn_type_id, proto_node, proto_node->data.fn_proto.params.length); for (; fn_type_id.next_param_index < fn_type_id.param_count; fn_type_id.next_param_index += 1) { AstNode *param_node = fn_proto->params.at(fn_type_id.next_param_index); diff --git a/src/analyze.hpp b/src/analyze.hpp index 2af001055..c22835f03 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -70,7 +70,7 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node); FnTableEntry *create_fn(AstNode *proto_node); FnTableEntry *create_fn_raw(FnInline inline_value, bool internal_linkage); -void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node); +void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc); AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index); FnTableEntry *scope_get_fn_if_root(Scope *scope); bool type_requires_comptime(TypeTableEntry *type_entry); diff --git a/src/ir.cpp b/src/ir.cpp index 48782ba90..ed4382d41 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -7866,7 +7866,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal impl_fn->fndef_scope = create_fndef_scope(impl_fn->fn_def_node, parent_scope, impl_fn); impl_fn->child_scope = &impl_fn->fndef_scope->base; FnTypeId inst_fn_type_id = {0}; - init_fn_type_id(&inst_fn_type_id, fn_proto_node); + init_fn_type_id(&inst_fn_type_id, fn_proto_node, call_param_count); inst_fn_type_id.param_count = 0; inst_fn_type_id.is_var_args = false; @@ -7875,7 +7875,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal GenericFnTypeId *generic_id = allocate(1); generic_id->fn_entry = fn_entry; generic_id->param_count = 0; - generic_id->params = allocate(src_param_count); + generic_id->params = allocate(call_param_count); size_t next_proto_i = 0; if (first_arg_ptr) { @@ -11483,7 +11483,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc assert(proto_node->type == NodeTypeFnProto); FnTypeId fn_type_id = {0}; - init_fn_type_id(&fn_type_id, proto_node); + init_fn_type_id(&fn_type_id, proto_node, proto_node->data.fn_proto.params.length); bool depends_on_compile_var = false;