authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-01 19:53:52-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-02 18:31:18-04:00
log30b2fb2fb545794beb44f80af308c4280d94deba
treea396b9777798cf123c0fcc19780de4b3988bdf11
parentd7bc7635c0e3324fa08fc809ec21ba014464ea03
signature Commit is signed but in an unrecognized format.

bug fixes


1 files changed, 20 insertions(+), 15 deletions(-)

src/analyze.cpp+20-15
......@@ -1642,6 +1642,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
16421642 field->bit_offset_in_host = 0;
16431643 } else {
16441644 // This is a byte-aligned field (both start and end) in a packed struct.
1645 host_int_bytes[gen_field_index] = field_type->size_in_bits / 8;
16451646 field->bit_offset_in_host = 0;
16461647 gen_field_index += 1;
16471648 // TODO: https://github.com/ziglang/zig/issues/1512
......@@ -2050,8 +2051,8 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
20502051
20512052 if (struct_type->data.structure.resolve_loop_flag) {
20522053 // TODO This is a problem. I believe it can be solved with lazy values.
2053 struct_type->size_in_bits = SIZE_MAX;;
2054 struct_type->abi_size = SIZE_MAX;;
2054 struct_type->size_in_bits = SIZE_MAX;
2055 struct_type->abi_size = SIZE_MAX;
20552056 struct_type->data.structure.resolve_status = ResolveStatusZeroBitsKnown;
20562057 struct_type->data.structure.resolve_loop_flag = false;
20572058 return ErrorNone;
......@@ -6335,15 +6336,25 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) {
63356336 assert(struct_type->data.structure.resolve_status >= ResolveStatusSizeKnown);
63366337 assert(struct_type->data.structure.fields || struct_type->data.structure.src_field_count == 0);
63376338
6339 // Do this early for the benefit of recursion.
6340 struct_type->llvm_type = type_has_bits(struct_type) ?
6341 LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&struct_type->name)) : LLVMVoidType();
63386342 AstNode *decl_node = struct_type->data.structure.decl_node;
63396343 assert(decl_node->type == NodeTypeContainerDecl);
6344 Scope *scope = &struct_type->data.structure.decls_scope->base;
6345 ZigType *import = get_scope_import(scope);
6346 unsigned dwarf_kind = ZigLLVMTag_DW_structure_type();
6347 struct_type->llvm_di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,
6348 dwarf_kind, buf_ptr(&struct_type->name),
6349 ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
6350 import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1));
6351
6352
63406353
63416354 size_t field_count = struct_type->data.structure.src_field_count;
63426355 size_t gen_field_count = struct_type->data.structure.gen_field_count;
63436356 LLVMTypeRef *element_types = allocate<LLVMTypeRef>(gen_field_count);
63446357
6345 Scope *scope = &struct_type->data.structure.decls_scope->base;
6346
63476358 size_t gen_field_index = 0;
63486359 bool packed = (struct_type->data.structure.layout == ContainerLayoutPacked);
63496360 size_t packed_bits_offset = 0;
......@@ -6394,17 +6405,11 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) {
63946405 gen_field_index += 1;
63956406 }
63966407
6397 struct_type->llvm_type = LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&struct_type->name));
6398 LLVMStructSetBody(struct_type->llvm_type, element_types, (unsigned)gen_field_count, packed);
6408 if (type_has_bits(struct_type)) {
6409 LLVMStructSetBody(struct_type->llvm_type, element_types, (unsigned)gen_field_count, packed);
6410 }
63996411
64006412 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count);
6401 ZigType *import = get_scope_import(scope);
6402 unsigned dwarf_kind = ZigLLVMTag_DW_structure_type();
6403 struct_type->llvm_di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,
6404 dwarf_kind, buf_ptr(&struct_type->name),
6405 ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
6406 import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1));
6407
64086413 size_t debug_field_index = 0;
64096414 for (size_t i = 0; i < field_count; i += 1) {
64106415 AstNode *field_node = decl_node->data.container_decl.fields.at(i);
......@@ -6501,6 +6506,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) {
65016506 get_llvm_di_type(g, tag_int_type), "");
65026507
65036508 enum_type->llvm_di_type = tag_di_type;
6509 enum_type->llvm_type = get_llvm_type(g, tag_int_type);
65046510}
65056511
65066512static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type) {
......@@ -6922,7 +6928,7 @@ static void resolve_llvm_types_fn(CodeGen *g, ZigType *fn_type) {
69226928static void resolve_llvm_types_anyerror(CodeGen *g) {
69236929 ZigType *entry = g->builtin_types.entry_global_error_set;
69246930 entry->llvm_type = get_llvm_type(g, g->err_tag_type);
6925 ZigList<ZigLLVMDIEnumerator *> err_enumerators;
6931 ZigList<ZigLLVMDIEnumerator *> err_enumerators = {};
69266932 // reserve index 0 to indicate no error
69276933 err_enumerators.append(ZigLLVMCreateDebugEnumerator(g->dbuilder, "(none)", 0));
69286934 for (size_t i = 1; i < g->errors_by_index.length; i += 1) {
......@@ -6945,7 +6951,6 @@ static void resolve_llvm_types_anyerror(CodeGen *g) {
69456951
69466952static void resolve_llvm_types(CodeGen *g, ZigType *type) {
69476953 assert(type_is_resolved(type, ResolveStatusSizeKnown));
6948 assert(type_has_bits(type));
69496954 switch (type->id) {
69506955 case ZigTypeIdInvalid:
69516956 case ZigTypeIdFloat: