From 664b41af65d3c9bbc8e09ffcaa91d404fe87d7a0 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 4 Jan 2017 01:56:21 -0500 Subject: fix debug information for function pointers in structs --- src/analyze.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index 30c151db53..155b83d997 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1349,6 +1349,18 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) { TypeTableEntry *field_type = type_struct_field->type_entry; + // if the field is a function, actually the debug info should be a pointer. + ZigLLVMDIType *field_di_type; + if (field_type->id == TypeTableEntryIdFn) { + TypeTableEntry *field_ptr_type = get_pointer_to_type(g, field_type, true); + uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_ptr_type->type_ref); + uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, field_ptr_type->type_ref); + field_di_type = ZigLLVMCreateDebugPointerType(g->dbuilder, field_type->di_type, + debug_size_in_bits, debug_align_in_bits, buf_ptr(&field_ptr_type->name)); + } else { + field_di_type = field_type->di_type; + } + assert(field_type->type_ref); assert(struct_type->type_ref); assert(struct_type->data.structure.complete); @@ -1362,7 +1374,7 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) { debug_size_in_bits, debug_align_in_bits, debug_offset_in_bits, - 0, field_type->di_type); + 0, field_di_type); assert(di_element_types[gen_field_index]); } -- cgit v1.2.3