| ... | @@ -1642,6 +1642,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { | ... | @@ -1642,6 +1642,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 1642 | field->bit_offset_in_host = 0; | 1642 | field->bit_offset_in_host = 0; |
| 1643 | } else { | 1643 | } else { |
| 1644 | // This is a byte-aligned field (both start and end) in a packed struct. | 1644 | // 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; |
| 1645 | field->bit_offset_in_host = 0; | 1646 | field->bit_offset_in_host = 0; |
| 1646 | gen_field_index += 1; | 1647 | gen_field_index += 1; |
| 1647 | // TODO: https://github.com/ziglang/zig/issues/1512 | 1648 | // TODO: https://github.com/ziglang/zig/issues/1512 |
| ... | @@ -2050,8 +2051,8 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { | ... | @@ -2050,8 +2051,8 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { |
| 2050 | | 2051 | |
| 2051 | if (struct_type->data.structure.resolve_loop_flag) { | 2052 | if (struct_type->data.structure.resolve_loop_flag) { |
| 2052 | // TODO This is a problem. I believe it can be solved with lazy values. | 2053 | // 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->size_in_bits = SIZE_MAX; |
| 2054 | struct_type->abi_size = SIZE_MAX;; | 2055 | struct_type->abi_size = SIZE_MAX; |
| 2055 | struct_type->data.structure.resolve_status = ResolveStatusZeroBitsKnown; | 2056 | struct_type->data.structure.resolve_status = ResolveStatusZeroBitsKnown; |
| 2056 | struct_type->data.structure.resolve_loop_flag = false; | 2057 | struct_type->data.structure.resolve_loop_flag = false; |
| 2057 | return ErrorNone; | 2058 | return ErrorNone; |
| ... | @@ -6335,15 +6336,25 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) { | ... | @@ -6335,15 +6336,25 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) { |
| 6335 | assert(struct_type->data.structure.resolve_status >= ResolveStatusSizeKnown); | 6336 | assert(struct_type->data.structure.resolve_status >= ResolveStatusSizeKnown); |
| 6336 | assert(struct_type->data.structure.fields || struct_type->data.structure.src_field_count == 0); | 6337 | assert(struct_type->data.structure.fields || struct_type->data.structure.src_field_count == 0); |
| 6337 | | 6338 | |
| | 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(); |
| 6338 | AstNode *decl_node = struct_type->data.structure.decl_node; | 6342 | AstNode *decl_node = struct_type->data.structure.decl_node; |
| 6339 | assert(decl_node->type == NodeTypeContainerDecl); | 6343 | 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 | |
| 6340 | | 6353 | |
| 6341 | size_t field_count = struct_type->data.structure.src_field_count; | 6354 | size_t field_count = struct_type->data.structure.src_field_count; |
| 6342 | size_t gen_field_count = struct_type->data.structure.gen_field_count; | 6355 | size_t gen_field_count = struct_type->data.structure.gen_field_count; |
| 6343 | LLVMTypeRef *element_types = allocate<LLVMTypeRef>(gen_field_count); | 6356 | LLVMTypeRef *element_types = allocate<LLVMTypeRef>(gen_field_count); |
| 6344 | | 6357 | |
| 6345 | Scope *scope = &struct_type->data.structure.decls_scope->base; | | |
| 6346 | | | |
| 6347 | size_t gen_field_index = 0; | 6358 | size_t gen_field_index = 0; |
| 6348 | bool packed = (struct_type->data.structure.layout == ContainerLayoutPacked); | 6359 | bool packed = (struct_type->data.structure.layout == ContainerLayoutPacked); |
| 6349 | size_t packed_bits_offset = 0; | 6360 | size_t packed_bits_offset = 0; |
| ... | @@ -6394,17 +6405,11 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) { | ... | @@ -6394,17 +6405,11 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) { |
| 6394 | gen_field_index += 1; | 6405 | gen_field_index += 1; |
| 6395 | } | 6406 | } |
| 6396 | | 6407 | |
| 6397 | struct_type->llvm_type = LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&struct_type->name)); | 6408 | if (type_has_bits(struct_type)) { |
| 6398 | LLVMStructSetBody(struct_type->llvm_type, element_types, (unsigned)gen_field_count, packed); | 6409 | LLVMStructSetBody(struct_type->llvm_type, element_types, (unsigned)gen_field_count, packed); |
| | 6410 | } |
| 6399 | | 6411 | |
| 6400 | ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count); | 6412 | 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 | | | |
| 6408 | size_t debug_field_index = 0; | 6413 | size_t debug_field_index = 0; |
| 6409 | for (size_t i = 0; i < field_count; i += 1) { | 6414 | for (size_t i = 0; i < field_count; i += 1) { |
| 6410 | AstNode *field_node = decl_node->data.container_decl.fields.at(i); | 6415 | 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) { | ... | @@ -6501,6 +6506,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) { |
| 6501 | get_llvm_di_type(g, tag_int_type), ""); | 6506 | get_llvm_di_type(g, tag_int_type), ""); |
| 6502 | | 6507 | |
| 6503 | enum_type->llvm_di_type = tag_di_type; | 6508 | enum_type->llvm_di_type = tag_di_type; |
| | 6509 | enum_type->llvm_type = get_llvm_type(g, tag_int_type); |
| 6504 | } | 6510 | } |
| 6505 | | 6511 | |
| 6506 | static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type) { | 6512 | static 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) { | ... | @@ -6922,7 +6928,7 @@ static void resolve_llvm_types_fn(CodeGen *g, ZigType *fn_type) { |
| 6922 | static void resolve_llvm_types_anyerror(CodeGen *g) { | 6928 | static void resolve_llvm_types_anyerror(CodeGen *g) { |
| 6923 | ZigType *entry = g->builtin_types.entry_global_error_set; | 6929 | ZigType *entry = g->builtin_types.entry_global_error_set; |
| 6924 | entry->llvm_type = get_llvm_type(g, g->err_tag_type); | 6930 | entry->llvm_type = get_llvm_type(g, g->err_tag_type); |
| 6925 | ZigList<ZigLLVMDIEnumerator *> err_enumerators; | 6931 | ZigList<ZigLLVMDIEnumerator *> err_enumerators = {}; |
| 6926 | // reserve index 0 to indicate no error | 6932 | // reserve index 0 to indicate no error |
| 6927 | err_enumerators.append(ZigLLVMCreateDebugEnumerator(g->dbuilder, "(none)", 0)); | 6933 | err_enumerators.append(ZigLLVMCreateDebugEnumerator(g->dbuilder, "(none)", 0)); |
| 6928 | for (size_t i = 1; i < g->errors_by_index.length; i += 1) { | 6934 | 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) { | ... | @@ -6945,7 +6951,6 @@ static void resolve_llvm_types_anyerror(CodeGen *g) { |
| 6945 | | 6951 | |
| 6946 | static void resolve_llvm_types(CodeGen *g, ZigType *type) { | 6952 | static void resolve_llvm_types(CodeGen *g, ZigType *type) { |
| 6947 | assert(type_is_resolved(type, ResolveStatusSizeKnown)); | 6953 | assert(type_is_resolved(type, ResolveStatusSizeKnown)); |
| 6948 | assert(type_has_bits(type)); | | |
| 6949 | switch (type->id) { | 6954 | switch (type->id) { |
| 6950 | case ZigTypeIdInvalid: | 6955 | case ZigTypeIdInvalid: |
| 6951 | case ZigTypeIdFloat: | 6956 | case ZigTypeIdFloat: |