authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-02 11:11:42-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-02 18:31:18-04:00
logddb8aa73f542d3432538e6de466ac216c89fd12b
treeed11f5829357daf610b3cb47c74c21a91dddd453
parent30b2fb2fb545794beb44f80af308c4280d94deba
signaturelock-open Commit is signed but in an unrecognized format.

more regression fixes


4 files changed, 117 insertions(+), 50 deletions(-)

src/analyze.cpp+91-30
...@@ -343,8 +343,9 @@ ZigType *get_promise_type(CodeGen *g, ZigType *result_type) {...@@ -343,8 +343,9 @@ ZigType *get_promise_type(CodeGen *g, ZigType *result_type) {
343 }343 }
344344
345 ZigType *entry = new_type_table_entry(ZigTypeIdPromise);345 ZigType *entry = new_type_table_entry(ZigTypeIdPromise);
346 entry->abi_size = g->pointer_size_bytes;346 entry->abi_size = g->builtin_types.entry_usize->abi_size;
347 entry->size_in_bits = g->pointer_size_bytes * 8;347 entry->size_in_bits = g->builtin_types.entry_usize->size_in_bits;
348 entry->abi_align = g->builtin_types.entry_usize->abi_align;
348 entry->data.promise.result_type = result_type;349 entry->data.promise.result_type = result_type;
349 buf_init_from_str(&entry->name, "promise");350 buf_init_from_str(&entry->name, "promise");
350 if (result_type != nullptr) {351 if (result_type != nullptr) {
...@@ -775,9 +776,6 @@ ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry) {...@@ -775,9 +776,6 @@ ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry) {
775776
776 ZigType *bound_fn_type = new_type_table_entry(ZigTypeIdBoundFn);777 ZigType *bound_fn_type = new_type_table_entry(ZigTypeIdBoundFn);
777 bound_fn_type->data.bound_fn.fn_type = fn_type;778 bound_fn_type->data.bound_fn.fn_type = fn_type;
778 bound_fn_type->abi_size = 0;
779 bound_fn_type->size_in_bits = 0;
780 bound_fn_type->abi_align = 0;
781779
782 buf_resize(&bound_fn_type->name, 0);780 buf_resize(&bound_fn_type->name, 0);
783 buf_appendf(&bound_fn_type->name, "(bound %s)", buf_ptr(&fn_type->name));781 buf_appendf(&bound_fn_type->name, "(bound %s)", buf_ptr(&fn_type->name));
...@@ -1248,6 +1246,9 @@ ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {...@@ -1248,6 +1246,9 @@ ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {
1248 err_set_type->data.error_set.err_count = 0;1246 err_set_type->data.error_set.err_count = 0;
1249 err_set_type->data.error_set.errors = nullptr;1247 err_set_type->data.error_set.errors = nullptr;
1250 err_set_type->data.error_set.infer_fn = fn_entry;1248 err_set_type->data.error_set.infer_fn = fn_entry;
1249 err_set_type->size_in_bits = g->builtin_types.entry_global_error_set->size_in_bits;
1250 err_set_type->abi_align = g->builtin_types.entry_global_error_set->abi_align;
1251 err_set_type->abi_size = g->builtin_types.entry_global_error_set->abi_size;
12511252
1252 return err_set_type;1253 return err_set_type;
1253}1254}
...@@ -1597,7 +1598,16 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -1597,7 +1598,16 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
15971598
1598 uint32_t *host_int_bytes = packed ? allocate<uint32_t>(struct_type->data.structure.gen_field_count) : nullptr;1599 uint32_t *host_int_bytes = packed ? allocate<uint32_t>(struct_type->data.structure.gen_field_count) : nullptr;
15991600
1600 // Compute offsets for all the fields.1601 // Resolve sizes of all the field types. Done before the offset loop because the offset
1602 // loop has to look ahead.
1603 for (size_t i = 0; i < field_count; i += 1) {
1604 TypeStructField *field = &struct_type->data.structure.fields[i];
1605 if ((err = type_resolve(g, field->type_entry, ResolveStatusSizeKnown))) {
1606 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
1607 return ErrorSemanticAnalyzeFail;
1608 }
1609 }
1610
1601 size_t packed_bits_offset = 0;1611 size_t packed_bits_offset = 0;
1602 size_t next_offset = 0;1612 size_t next_offset = 0;
1603 size_t first_packed_bits_offset_misalign = SIZE_MAX;1613 size_t first_packed_bits_offset_misalign = SIZE_MAX;
...@@ -1739,6 +1749,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {...@@ -1739,6 +1749,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {
1739 // unset temporary flag1749 // unset temporary flag
1740 union_type->data.unionation.resolve_loop_flag = false;1750 union_type->data.unionation.resolve_loop_flag = false;
1741 union_type->data.unionation.resolve_status = ResolveStatusAlignmentKnown;1751 union_type->data.unionation.resolve_status = ResolveStatusAlignmentKnown;
1752 union_type->data.unionation.most_aligned_union_member = most_aligned_union_member;
17421753
1743 ZigType *tag_type = union_type->data.unionation.tag_type;1754 ZigType *tag_type = union_type->data.unionation.tag_type;
1744 if (tag_type != nullptr && type_has_bits(tag_type)) {1755 if (tag_type != nullptr && type_has_bits(tag_type)) {
...@@ -1788,6 +1799,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -1788,6 +1799,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
1788 assert(decl_node->type == NodeTypeContainerDecl);1799 assert(decl_node->type == NodeTypeContainerDecl);
17891800
1790 uint32_t field_count = union_type->data.unionation.src_field_count;1801 uint32_t field_count = union_type->data.unionation.src_field_count;
1802 ZigType *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;
17911803
1792 assert(union_type->data.unionation.fields);1804 assert(union_type->data.unionation.fields);
17931805
...@@ -1827,13 +1839,18 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -1827,13 +1839,18 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
1827 union_size_in_bits = max(union_size_in_bits, field_type->size_in_bits);1839 union_size_in_bits = max(union_size_in_bits, field_type->size_in_bits);
1828 }1840 }
18291841
1842 // The union itself for now has to be treated as being independently aligned.
1843 // See https://github.com/ziglang/zig/issues/2166.
1844 if (most_aligned_union_member != nullptr) {
1845 union_abi_size = align_forward(union_abi_size, most_aligned_union_member->abi_align);
1846 }
1847
1830 // unset temporary flag1848 // unset temporary flag
1831 union_type->data.unionation.resolve_loop_flag = false;1849 union_type->data.unionation.resolve_loop_flag = false;
1832 union_type->data.unionation.resolve_status = ResolveStatusSizeKnown;1850 union_type->data.unionation.resolve_status = ResolveStatusSizeKnown;
1833 union_type->data.unionation.union_abi_size = union_abi_size;1851 union_type->data.unionation.union_abi_size = union_abi_size;
18341852
1835 ZigType *tag_type = union_type->data.unionation.tag_type;1853 ZigType *tag_type = union_type->data.unionation.tag_type;
1836 ZigType *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;
1837 if (tag_type != nullptr && type_has_bits(tag_type)) {1854 if (tag_type != nullptr && type_has_bits(tag_type)) {
1838 if ((err = type_resolve(g, tag_type, ResolveStatusSizeKnown))) {1855 if ((err = type_resolve(g, tag_type, ResolveStatusSizeKnown))) {
1839 union_type->data.unionation.resolve_status = ResolveStatusInvalid;1856 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
...@@ -6340,16 +6357,25 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) {...@@ -6340,16 +6357,25 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) {
6340 struct_type->llvm_type = type_has_bits(struct_type) ?6357 struct_type->llvm_type = type_has_bits(struct_type) ?
6341 LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&struct_type->name)) : LLVMVoidType();6358 LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&struct_type->name)) : LLVMVoidType();
6342 AstNode *decl_node = struct_type->data.structure.decl_node;6359 AstNode *decl_node = struct_type->data.structure.decl_node;
6343 assert(decl_node->type == NodeTypeContainerDecl);6360 ZigLLVMDIFile *di_file;
6344 Scope *scope = &struct_type->data.structure.decls_scope->base;6361 ZigLLVMDIScope *di_scope;
6345 ZigType *import = get_scope_import(scope);6362 unsigned line;
6363 if (decl_node != nullptr) {
6364 assert(decl_node->type == NodeTypeContainerDecl);
6365 Scope *scope = &struct_type->data.structure.decls_scope->base;
6366 ZigType *import = get_scope_import(scope);
6367 di_file = import->data.structure.root_struct->di_file;
6368 di_scope = ZigLLVMFileToScope(di_file);
6369 line = decl_node->line + 1;
6370 } else {
6371 di_file = nullptr;
6372 di_scope = ZigLLVMCompileUnitToScope(g->compile_unit);
6373 line = 0;
6374 }
6346 unsigned dwarf_kind = ZigLLVMTag_DW_structure_type();6375 unsigned dwarf_kind = ZigLLVMTag_DW_structure_type();
6347 struct_type->llvm_di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,6376 struct_type->llvm_di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,
6348 dwarf_kind, buf_ptr(&struct_type->name),6377 dwarf_kind, buf_ptr(&struct_type->name),
6349 ZigLLVMFileToScope(import->data.structure.root_struct->di_file),6378 di_scope, di_file, line);
6350 import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1));
6351
6352
63536379
6354 size_t field_count = struct_type->data.structure.src_field_count;6380 size_t field_count = struct_type->data.structure.src_field_count;
6355 size_t gen_field_count = struct_type->data.structure.gen_field_count;6381 size_t gen_field_count = struct_type->data.structure.gen_field_count;
...@@ -6412,7 +6438,6 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) {...@@ -6412,7 +6438,6 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) {
6412 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count);6438 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count);
6413 size_t debug_field_index = 0;6439 size_t debug_field_index = 0;
6414 for (size_t i = 0; i < field_count; i += 1) {6440 for (size_t i = 0; i < field_count; i += 1) {
6415 AstNode *field_node = decl_node->data.container_decl.fields.at(i);
6416 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];6441 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];
6417 size_t gen_field_index = type_struct_field->gen_index;6442 size_t gen_field_index = type_struct_field->gen_index;
6418 if (gen_field_index == SIZE_MAX) {6443 if (gen_field_index == SIZE_MAX) {
...@@ -6445,9 +6470,16 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) {...@@ -6445,9 +6470,16 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) {
6445 debug_align_in_bits = 8 * field_type->abi_align;6470 debug_align_in_bits = 8 * field_type->abi_align;
6446 debug_offset_in_bits = 8 * type_struct_field->offset;6471 debug_offset_in_bits = 8 * type_struct_field->offset;
6447 }6472 }
6473 unsigned line;
6474 if (decl_node != nullptr) {
6475 AstNode *field_node = decl_node->data.container_decl.fields.at(i);
6476 line = field_node->line + 1;
6477 } else {
6478 line = 0;
6479 }
6448 di_element_types[debug_field_index] = ZigLLVMCreateDebugMemberType(g->dbuilder,6480 di_element_types[debug_field_index] = ZigLLVMCreateDebugMemberType(g->dbuilder,
6449 ZigLLVMTypeToScope(struct_type->llvm_di_type), buf_ptr(type_struct_field->name),6481 ZigLLVMTypeToScope(struct_type->llvm_di_type), buf_ptr(type_struct_field->name),
6450 import->data.structure.root_struct->di_file, (unsigned)(field_node->line + 1),6482 di_file, line,
6451 debug_size_in_bits,6483 debug_size_in_bits,
6452 debug_align_in_bits,6484 debug_align_in_bits,
6453 debug_offset_in_bits,6485 debug_offset_in_bits,
...@@ -6459,9 +6491,9 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) {...@@ -6459,9 +6491,9 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type) {
6459 uint64_t debug_size_in_bits = get_store_size_in_bits(struct_type->size_in_bits);6491 uint64_t debug_size_in_bits = get_store_size_in_bits(struct_type->size_in_bits);
6460 uint64_t debug_align_in_bits = 8*struct_type->abi_align;6492 uint64_t debug_align_in_bits = 8*struct_type->abi_align;
6461 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,6493 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
6462 ZigLLVMFileToScope(import->data.structure.root_struct->di_file),6494 di_scope,
6463 buf_ptr(&struct_type->name),6495 buf_ptr(&struct_type->name),
6464 import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),6496 di_file, line,
6465 debug_size_in_bits,6497 debug_size_in_bits,
6466 debug_align_in_bits,6498 debug_align_in_bits,
6467 0, nullptr, di_element_types, (int)debug_field_count, 0, nullptr, "");6499 0, nullptr, di_element_types, (int)debug_field_count, 0, nullptr, "");
...@@ -6512,19 +6544,14 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) {...@@ -6512,19 +6544,14 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) {
6512static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type) {6544static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type) {
6513 ZigType *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;6545 ZigType *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;
6514 ZigType *tag_type = union_type->data.unionation.tag_type;6546 ZigType *tag_type = union_type->data.unionation.tag_type;
6515 if (tag_type == nullptr || !type_has_bits(tag_type)) {
6516 assert(most_aligned_union_member != nullptr);
6517 assert(union_type->data.unionation.union_abi_size >= most_aligned_union_member->abi_size);
6518 union_type->llvm_type = get_llvm_type(g, most_aligned_union_member);
6519 union_type->llvm_di_type = get_llvm_di_type(g, most_aligned_union_member);
6520 return;
6521 }
6522 if (most_aligned_union_member == nullptr) {6547 if (most_aligned_union_member == nullptr) {
6523 union_type->llvm_type = get_llvm_type(g, tag_type);6548 union_type->llvm_type = get_llvm_type(g, tag_type);
6524 union_type->llvm_di_type = get_llvm_di_type(g, tag_type);6549 union_type->llvm_di_type = get_llvm_di_type(g, tag_type);
6525 return;6550 return;
6526 }6551 }
65276552
6553 // Do this first for the benefit of recursive calls.
6554 union_type->llvm_type = LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&union_type->name));
6528 Scope *scope = &union_type->data.unionation.decls_scope->base;6555 Scope *scope = &union_type->data.unionation.decls_scope->base;
6529 ZigType *import = get_scope_import(scope);6556 ZigType *import = get_scope_import(scope);
6530 AstNode *decl_node = union_type->data.unionation.decl_node;6557 AstNode *decl_node = union_type->data.unionation.decl_node;
...@@ -6535,6 +6562,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type) {...@@ -6535,6 +6562,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type) {
6535 ZigLLVMFileToScope(import->data.structure.root_struct->di_file),6562 ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
6536 import->data.structure.root_struct->di_file, (unsigned)(line + 1));6563 import->data.structure.root_struct->di_file, (unsigned)(line + 1));
65376564
6565
6538 uint32_t gen_field_count = union_type->data.unionation.gen_field_count;6566 uint32_t gen_field_count = union_type->data.unionation.gen_field_count;
6539 ZigLLVMDIType **union_inner_di_types = allocate<ZigLLVMDIType*>(gen_field_count);6567 ZigLLVMDIType **union_inner_di_types = allocate<ZigLLVMDIType*>(gen_field_count);
6540 uint32_t field_count = union_type->data.unionation.src_field_count;6568 uint32_t field_count = union_type->data.unionation.src_field_count;
...@@ -6555,7 +6583,40 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type) {...@@ -6555,7 +6583,40 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type) {
6555 0, get_llvm_di_type(g, union_field->type_entry));6583 0, get_llvm_di_type(g, union_field->type_entry));
65566584
6557 }6585 }
6558 union_type->llvm_type = LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&union_type->name));6586
6587 if (tag_type == nullptr || !type_has_bits(tag_type)) {
6588 assert(most_aligned_union_member != nullptr);
6589
6590 size_t padding_bytes = union_type->data.unionation.union_abi_size - most_aligned_union_member->abi_size;
6591 (void)get_llvm_type(g, most_aligned_union_member);
6592 if (padding_bytes > 0) {
6593 ZigType *u8_type = get_int_type(g, false, 8);
6594 ZigType *padding_array = get_array_type(g, u8_type, padding_bytes);
6595 LLVMTypeRef union_element_types[] = {
6596 most_aligned_union_member->llvm_type,
6597 get_llvm_type(g, padding_array),
6598 };
6599 LLVMStructSetBody(union_type->llvm_type, union_element_types, 2, false);
6600 } else {
6601 LLVMStructSetBody(union_type->llvm_type, &most_aligned_union_member->llvm_type, 1, false);
6602 }
6603 union_type->data.unionation.union_llvm_type = union_type->llvm_type;
6604 union_type->data.unionation.gen_tag_index = SIZE_MAX;
6605 union_type->data.unionation.gen_union_index = SIZE_MAX;
6606
6607 // create debug type for union
6608 ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder,
6609 ZigLLVMFileToScope(import->data.structure.root_struct->di_file), buf_ptr(&union_type->name),
6610 import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
6611 union_type->data.unionation.union_abi_size * 8,
6612 most_aligned_union_member->abi_align * 8,
6613 0, union_inner_di_types,
6614 gen_field_count, 0, "");
6615
6616 ZigLLVMReplaceTemporary(g->dbuilder, union_type->llvm_di_type, replacement_di_type);
6617 union_type->llvm_di_type = replacement_di_type;
6618 return;
6619 }
65596620
6560 LLVMTypeRef union_type_ref;6621 LLVMTypeRef union_type_ref;
6561 size_t padding_bytes = union_type->data.unionation.union_abi_size - most_aligned_union_member->abi_size;6622 size_t padding_bytes = union_type->data.unionation.union_abi_size - most_aligned_union_member->abi_size;
...@@ -7018,8 +7079,8 @@ LLVMTypeRef get_llvm_type(CodeGen *g, ZigType *type) {...@@ -7018,8 +7079,8 @@ LLVMTypeRef get_llvm_type(CodeGen *g, ZigType *type) {
7018 resolve_llvm_types(g, type);7079 resolve_llvm_types(g, type);
7019 assert(type->llvm_type != nullptr);7080 assert(type->llvm_type != nullptr);
7020 assert(type->llvm_di_type != nullptr);7081 assert(type->llvm_di_type != nullptr);
7021 assert(type->abi_size == LLVMABISizeOfType(g->target_data_ref, type->llvm_type));7082 assert(type->abi_size == 0 || type->abi_size == LLVMABISizeOfType(g->target_data_ref, type->llvm_type));
7022 assert(type->abi_align == LLVMABIAlignmentOfType(g->target_data_ref, type->llvm_type));7083 assert(type->abi_align == 0 || type->abi_align == LLVMABIAlignmentOfType(g->target_data_ref, type->llvm_type));
7023 return type->llvm_type;7084 return type->llvm_type;
7024}7085}
70257086
...@@ -7029,7 +7090,7 @@ ZigLLVMDIType *get_llvm_di_type(CodeGen *g, ZigType *type) {...@@ -7029,7 +7090,7 @@ ZigLLVMDIType *get_llvm_di_type(CodeGen *g, ZigType *type) {
7029 resolve_llvm_types(g, type);7090 resolve_llvm_types(g, type);
7030 assert(type->llvm_type != nullptr);7091 assert(type->llvm_type != nullptr);
7031 assert(type->llvm_di_type != nullptr);7092 assert(type->llvm_di_type != nullptr);
7032 assert(type->abi_size == LLVMABISizeOfType(g->target_data_ref, type->llvm_type));7093 assert(type->abi_size == 0 || type->abi_size == LLVMABISizeOfType(g->target_data_ref, type->llvm_type));
7033 assert(type->abi_align == LLVMABIAlignmentOfType(g->target_data_ref, type->llvm_type));7094 assert(type->abi_align == 0 || type->abi_align == LLVMABIAlignmentOfType(g->target_data_ref, type->llvm_type));
7034 return type->llvm_di_type;7095 return type->llvm_di_type;
7035}7096}
src/codegen.cpp+22-14
...@@ -498,6 +498,8 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) {...@@ -498,6 +498,8 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) {
498 } else {498 } else {
499 assert(entry->value->id == TldIdFn);499 assert(entry->value->id == TldIdFn);
500 TldFn *tld_fn = reinterpret_cast<TldFn *>(entry->value);500 TldFn *tld_fn = reinterpret_cast<TldFn *>(entry->value);
501 // Make the raw_type_ref populated
502 (void)get_llvm_type(g, tld_fn->fn_entry->type_entry);
501 tld_fn->fn_entry->llvm_value = LLVMAddFunction(g->module, buf_ptr(symbol_name),503 tld_fn->fn_entry->llvm_value = LLVMAddFunction(g->module, buf_ptr(symbol_name),
502 tld_fn->fn_entry->type_entry->data.fn.raw_type_ref);504 tld_fn->fn_entry->type_entry->data.fn.raw_type_ref);
503 fn_table_entry->llvm_value = LLVMConstBitCast(tld_fn->fn_entry->llvm_value,505 fn_table_entry->llvm_value = LLVMConstBitCast(tld_fn->fn_entry->llvm_value,
...@@ -6292,14 +6294,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -6292,14 +6294,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
6292 }6294 }
6293 case ZigTypeIdUnion:6295 case ZigTypeIdUnion:
6294 {6296 {
6295 BREAKPOINT; // TODO rework this logic to take into account the new layout
6296
6297 // Force type_entry->data.unionation.union_llvm_type to get resolved6297 // Force type_entry->data.unionation.union_llvm_type to get resolved
6298 (void)get_llvm_type(g, type_entry);6298 (void)get_llvm_type(g, type_entry);
62996299
6300 LLVMTypeRef union_type_ref = type_entry->data.unionation.union_llvm_type;
6301 assert(union_type_ref != nullptr);
6302
6303 if (type_entry->data.unionation.gen_field_count == 0) {6300 if (type_entry->data.unionation.gen_field_count == 0) {
6304 if (type_entry->data.unionation.tag_type == nullptr) {6301 if (type_entry->data.unionation.tag_type == nullptr) {
6305 return nullptr;6302 return nullptr;
...@@ -6309,6 +6306,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -6309,6 +6306,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
6309 }6306 }
6310 }6307 }
63116308
6309 LLVMTypeRef union_type_ref = type_entry->data.unionation.union_llvm_type;
6310 assert(union_type_ref != nullptr);
6311
6312 LLVMValueRef union_value_ref;6312 LLVMValueRef union_value_ref;
6313 bool make_unnamed_struct;6313 bool make_unnamed_struct;
6314 ConstExprValue *payload_value = const_val->data.x_union.payload;6314 ConstExprValue *payload_value = const_val->data.x_union.payload;
...@@ -7740,8 +7740,15 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -7740,8 +7740,15 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
7740 buf_appendf(contents, "pub const valgrind_support = %s;\n", bool_to_str(want_valgrind_support(g)));7740 buf_appendf(contents, "pub const valgrind_support = %s;\n", bool_to_str(want_valgrind_support(g)));
7741 buf_appendf(contents, "pub const position_independent_code = %s;\n", bool_to_str(g->have_pic));7741 buf_appendf(contents, "pub const position_independent_code = %s;\n", bool_to_str(g->have_pic));
77427742
7743 buf_appendf(contents, "pub const __zig_test_fn_slice = {}; // overwritten later\n");7743 if (g->is_test_build) {
77447744 buf_appendf(contents,
7745 "const TestFn = struct {\n"
7746 "name: []const u8,\n"
7747 "func: fn()anyerror!void,\n"
7748 "};\n"
7749 "pub const test_functions = {}; // overwritten later\n"
7750 );
7751 }
77457752
7746 return contents;7753 return contents;
7747}7754}
...@@ -8148,6 +8155,8 @@ static ZigPackage *create_panic_pkg(CodeGen *g) {...@@ -8148,6 +8155,8 @@ static ZigPackage *create_panic_pkg(CodeGen *g) {
8148}8155}
81498156
8150static void create_test_compile_var_and_add_test_runner(CodeGen *g) {8157static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
8158 Error err;
8159
8151 assert(g->is_test_build);8160 assert(g->is_test_build);
81528161
8153 if (g->test_fns.length == 0) {8162 if (g->test_fns.length == 0) {
...@@ -8155,14 +8164,13 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {...@@ -8155,14 +8164,13 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
8155 exit(0);8164 exit(0);
8156 }8165 }
81578166
8158 ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
8159 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0, false);
8160 ZigType *str_type = get_slice_type(g, u8_ptr_type);
8161 ZigType *fn_type = get_test_fn_type(g);8167 ZigType *fn_type = get_test_fn_type(g);
81628168
8163 const char *field_names[] = { "name", "func", };8169 ConstExprValue *test_fn_type_val = get_builtin_value(g, "TestFn");
8164 ZigType *field_types[] = { str_type, fn_type, };8170 assert(test_fn_type_val->type->id == ZigTypeIdMetaType);
8165 ZigType *struct_type = get_struct_type(g, "ZigTestFn", field_names, field_types, 2);8171 ZigType *struct_type = test_fn_type_val->data.x_type;
8172 if ((err = type_resolve(g, struct_type, ResolveStatusSizeKnown)))
8173 zig_unreachable();
81668174
8167 ConstExprValue *test_fn_array = create_const_vals(1);8175 ConstExprValue *test_fn_array = create_const_vals(1);
8168 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length);8176 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length);
...@@ -8194,7 +8202,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {...@@ -8194,7 +8202,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
81948202
8195 ConstExprValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true);8203 ConstExprValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true);
81968204
8197 update_compile_var(g, buf_create_from_str("__zig_test_fn_slice"), test_fn_slice);8205 update_compile_var(g, buf_create_from_str("test_functions"), test_fn_slice);
8198 g->test_runner_package = create_test_runner_pkg(g);8206 g->test_runner_package = create_test_runner_pkg(g);
8199 g->test_runner_import = add_special_code(g, g->test_runner_package, "test_runner.zig");8207 g->test_runner_import = add_special_code(g, g->test_runner_package, "test_runner.zig");
8200}8208}
src/ir.cpp+3-5
...@@ -8945,11 +8945,9 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp...@@ -8945,11 +8945,9 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp
89458945
8946 err_set_type->data.error_set.err_count = intersection_list.length;8946 err_set_type->data.error_set.err_count = intersection_list.length;
8947 err_set_type->data.error_set.errors = intersection_list.items;8947 err_set_type->data.error_set.errors = intersection_list.items;
8948 if (intersection_list.length != 0) {8948 err_set_type->size_in_bits = ira->codegen->builtin_types.entry_global_error_set->size_in_bits;
8949 err_set_type->size_in_bits = ira->codegen->builtin_types.entry_global_error_set->size_in_bits;8949 err_set_type->abi_align = ira->codegen->builtin_types.entry_global_error_set->abi_align;
8950 err_set_type->abi_align = ira->codegen->builtin_types.entry_global_error_set->abi_align;8950 err_set_type->abi_size = ira->codegen->builtin_types.entry_global_error_set->abi_size;
8951 err_set_type->abi_size = ira->codegen->builtin_types.entry_global_error_set->abi_size;
8952 }
89538951
8954 buf_appendf(&err_set_type->name, "}");8952 buf_appendf(&err_set_type->name, "}");
89558953
std/special/test_runner.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const io = std.io;2const io = std.io;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const test_fn_list = builtin.__zig_test_fn_slice;4const test_fn_list = builtin.test_functions;
5const warn = std.debug.warn;5const warn = std.debug.warn;
66
7pub fn main() !void {7pub fn main() !void {