zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 664b41af65d3c9bbc8e09ffcaa91d404fe87d7a0 (tree)
parent dbb1018ca678652423e237bb5465f9b20f88c986
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Wed,  4 Jan 2017 01:56:21 -0500

fix debug information for function pointers in structs

Diffstat:
Msrc/analyze.cpp | 14+++++++++++++-
Msrc/ir.cpp | 4+++-
2 files changed, 16 insertions(+), 2 deletions(-)

diff --git 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]); } diff --git a/src/ir.cpp b/src/ir.cpp @@ -4925,7 +4925,9 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, name = buf_alloc(); buf_append_buf(name, &fn_entry->symbol_name); buf_appendf(name, "("); - // TODO render args + // TODO render args. note that fn_type_id is likely not complete + // at this time. + // probably have to render them from the fn scope buf_appendf(name, ")"); } else { name = buf_sprintf("(anonymous %s at %s:%zu:%zu)", container_string(kind),