From 94bbb46ca602be0ea0df97c207a98734ac459a0f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 29 Aug 2019 10:24:24 -0400 Subject: [PATCH] fix not fully resolving debug info for structs causing llvm error --- src/all_types.hpp | 2 ++ src/analyze.cpp | 15 ++++++++++++++- src/codegen.cpp | 6 ++++++ src/list.hpp | 11 +++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/all_types.hpp b/src/all_types.hpp index 48323e58ad..e55f10d5e2 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1214,6 +1214,7 @@ struct ZigTypeStruct { HashMap fields_by_name; RootStruct *root_struct; uint32_t *host_int_bytes; // available for packed structs, indexed by gen_index + size_t llvm_full_type_queue_index; uint32_t src_field_count; uint32_t gen_field_count; @@ -1861,6 +1862,7 @@ struct CodeGen { ZigList errors_by_index; ZigList caches_to_release; size_t largest_err_name_len; + ZigList type_resolve_stack; ZigPackage *std_package; ZigPackage *panic_package; diff --git a/src/analyze.cpp b/src/analyze.cpp index 9ae7e99547..2c934bcf69 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -7271,7 +7271,13 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS di_scope, di_file, line); struct_type->data.structure.resolve_status = ResolveStatusLLVMFwdDecl; - if (ResolveStatusLLVMFwdDecl >= wanted_resolve_status) return; + if (ResolveStatusLLVMFwdDecl >= wanted_resolve_status) { + struct_type->data.structure.llvm_full_type_queue_index = g->type_resolve_stack.length; + g->type_resolve_stack.append(struct_type); + return; + } else { + struct_type->data.structure.llvm_full_type_queue_index = SIZE_MAX; + } } size_t field_count = struct_type->data.structure.src_field_count; @@ -7475,6 +7481,13 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS ZigLLVMReplaceTemporary(g->dbuilder, struct_type->llvm_di_type, replacement_di_type); struct_type->llvm_di_type = replacement_di_type; struct_type->data.structure.resolve_status = ResolveStatusLLVMFull; + if (struct_type->data.structure.llvm_full_type_queue_index != SIZE_MAX) { + ZigType *last = g->type_resolve_stack.last(); + assert(last->id == ZigTypeIdStruct); + last->data.structure.llvm_full_type_queue_index = struct_type->data.structure.llvm_full_type_queue_index; + g->type_resolve_stack.swap_remove(struct_type->data.structure.llvm_full_type_queue_index); + struct_type->data.structure.llvm_full_type_queue_index = SIZE_MAX; + } } static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatus wanted_resolve_status) { diff --git a/src/codegen.cpp b/src/codegen.cpp index eda7a75d38..4065994d80 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -7208,6 +7208,12 @@ static void do_code_gen(CodeGen *g) { LLVMSetModuleInlineAsm(g->module, buf_ptr(&g->global_asm)); } + while (g->type_resolve_stack.length != 0) { + ZigType *ty = g->type_resolve_stack.last(); + if (type_resolve(g, ty, ResolveStatusLLVMFull)) + zig_unreachable(); + } + ZigLLVMDIBuilderFinalize(g->dbuilder); if (g->verbose_llvm_ir) { diff --git a/src/list.hpp b/src/list.hpp index f838e44a5b..8dce75f2b8 100644 --- a/src/list.hpp +++ b/src/list.hpp @@ -74,6 +74,17 @@ struct ZigList { capacity = better_capacity; } + T swap_remove(size_t index) { + if (length - 1 == index) return pop(); + + assert(index != SIZE_MAX); + assert(index < length); + + T old_item = items[index]; + items[index] = pop(); + return old_item; + } + T *items; size_t length; size_t capacity;