diff --git a/src/analyze.cpp b/src/analyze.cpp index acf921f35a..cdc0914fae 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -506,6 +506,16 @@ static void preview_fn_def(CodeGen *g, ImportTableEntry *import, AstNode *node, fn_table_entry->internal_linkage = is_internal; fn_table_entry->calling_convention = is_internal ? LLVMFastCallConv : LLVMCCallConv; fn_table_entry->label_table.init(8); + fn_table_entry->member_of_struct = struct_type; + + if (struct_type) { + buf_resize(&fn_table_entry->symbol_name, 0); + buf_appendf(&fn_table_entry->symbol_name, "%s_%s", + buf_ptr(&struct_type->name), + buf_ptr(proto_name)); + } else { + buf_init_from_buf(&fn_table_entry->symbol_name, proto_name); + } g->fn_protos.append(fn_table_entry); g->fn_defs.append(fn_table_entry); @@ -556,6 +566,8 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import, fn_table_entry->import_entry = import; fn_table_entry->label_table.init(8); + buf_init_from_buf(&fn_table_entry->symbol_name, &fn_proto->data.fn_proto.name); + resolve_function_proto(g, fn_proto, fn_table_entry, import); Buf *name = &fn_proto->data.fn_proto.name; diff --git a/src/analyze.hpp b/src/analyze.hpp index e71261eb58..a578a0f4e3 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -138,6 +138,8 @@ struct FnTableEntry { ZigList fn_attr_list; // Required to be a pre-order traversal of the AST. (parents must come before children) ZigList all_block_contexts; + TypeTableEntry *member_of_struct; + Buf symbol_name; // reminder: hash tables must be initialized before use HashMap label_table; diff --git a/src/codegen.cpp b/src/codegen.cpp index 0a784f8071..08fc24fef3 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1503,7 +1503,8 @@ static void do_code_gen(CodeGen *g) { gen_param_index += 1; } LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, param_count, fn_proto->is_var_args); - LLVMValueRef fn = LLVMAddFunction(g->module, buf_ptr(&fn_proto->name), function_type); + + LLVMValueRef fn = LLVMAddFunction(g->module, buf_ptr(&fn_table_entry->symbol_name), function_type); for (int attr_i = 0; attr_i < fn_table_entry->fn_attr_list.length; attr_i += 1) { FnAttrId attr_id = fn_table_entry->fn_attr_list.at(attr_i); @@ -1542,7 +1543,8 @@ static void do_code_gen(CodeGen *g) { unsigned flags = 0; bool is_optimized = g->build_type == CodeGenBuildTypeRelease; LLVMZigDISubprogram *subprogram = LLVMZigCreateFunction(g->dbuilder, - import->block_context->di_scope, buf_ptr(&fn_proto->name), "", import->di_file, line_number, + import->block_context->di_scope, buf_ptr(&fn_table_entry->symbol_name), "", + import->di_file, line_number, create_di_function_type(g, fn_proto, import->di_file), fn_table_entry->internal_linkage, is_definition, scope_line, flags, is_optimized, fn);