Commit 664b41af65

Andrew Kelley <superjoe30@gmail.com>
2017-01-04 07:56:21
fix debug information for function pointers in structs
1 parent dbb1018
Changed files (2)
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]);
     }
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),