authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-04 16:46:24-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-04 17:04:59-05:00
logf247a905419f47f794837c3818636553eebb929c
tree65b1f3b5a106a68537d31c206dadc3e71dbcff35
parent6cbd1ac51af4300ef11373d16771cf011fb6e572
signaturelock-open Commit is signed but in an unrecognized format.

get_codegen_ptr_type returns possible error

And fix most of the fallout. This also makes optional pointers not require resolving zero bits, because the comptime value struct layout no longer depends on whether the type has zero bits. Thanks to @LemonBoy for the behavior test case Closes #4357 Closes #4359

5 files changed, 439 insertions(+), 300 deletions(-)

src/analyze.cpp+244-141
...@@ -597,7 +597,7 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_con...@@ -597,7 +597,7 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_con
597 entry->size_in_bits = SIZE_MAX;597 entry->size_in_bits = SIZE_MAX;
598 entry->abi_align = UINT32_MAX;598 entry->abi_align = UINT32_MAX;
599 } else if (type_is_resolved(child_type, ResolveStatusZeroBitsKnown)) {599 } else if (type_is_resolved(child_type, ResolveStatusZeroBitsKnown)) {
600 if (type_has_bits(child_type)) {600 if (type_has_bits(g, child_type)) {
601 entry->abi_size = g->builtin_types.entry_usize->abi_size;601 entry->abi_size = g->builtin_types.entry_usize->abi_size;
602 entry->size_in_bits = g->builtin_types.entry_usize->size_in_bits;602 entry->size_in_bits = g->builtin_types.entry_usize->size_in_bits;
603 entry->abi_align = g->builtin_types.entry_usize->abi_align;603 entry->abi_align = g->builtin_types.entry_usize->abi_align;
...@@ -660,11 +660,11 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {...@@ -660,11 +660,11 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
660 buf_resize(&entry->name, 0);660 buf_resize(&entry->name, 0);
661 buf_appendf(&entry->name, "?%s", buf_ptr(&child_type->name));661 buf_appendf(&entry->name, "?%s", buf_ptr(&child_type->name));
662662
663 if (!type_has_bits(child_type)) {663 if (!type_has_bits(g, child_type)) {
664 entry->size_in_bits = g->builtin_types.entry_bool->size_in_bits;664 entry->size_in_bits = g->builtin_types.entry_bool->size_in_bits;
665 entry->abi_size = g->builtin_types.entry_bool->abi_size;665 entry->abi_size = g->builtin_types.entry_bool->abi_size;
666 entry->abi_align = g->builtin_types.entry_bool->abi_align;666 entry->abi_align = g->builtin_types.entry_bool->abi_align;
667 } else if (type_is_nonnull_ptr(child_type) || child_type->id == ZigTypeIdErrorSet) {667 } else if (type_is_nonnull_ptr(g, child_type) || child_type->id == ZigTypeIdErrorSet) {
668 // This is an optimization but also is necessary for calling C668 // This is an optimization but also is necessary for calling C
669 // functions where all pointers are optional pointers.669 // functions where all pointers are optional pointers.
670 // Function types are technically pointers.670 // Function types are technically pointers.
...@@ -729,8 +729,8 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa...@@ -729,8 +729,8 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa
729 entry->data.error_union.err_set_type = err_set_type;729 entry->data.error_union.err_set_type = err_set_type;
730 entry->data.error_union.payload_type = payload_type;730 entry->data.error_union.payload_type = payload_type;
731731
732 if (!type_has_bits(payload_type)) {732 if (!type_has_bits(g, payload_type)) {
733 if (type_has_bits(err_set_type)) {733 if (type_has_bits(g, err_set_type)) {
734 entry->size_in_bits = err_set_type->size_in_bits;734 entry->size_in_bits = err_set_type->size_in_bits;
735 entry->abi_size = err_set_type->abi_size;735 entry->abi_size = err_set_type->abi_size;
736 entry->abi_align = err_set_type->abi_align;736 entry->abi_align = err_set_type->abi_align;
...@@ -739,7 +739,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa...@@ -739,7 +739,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa
739 entry->abi_size = 0;739 entry->abi_size = 0;
740 entry->abi_align = 0;740 entry->abi_align = 0;
741 }741 }
742 } else if (!type_has_bits(err_set_type)) {742 } else if (!type_has_bits(g, err_set_type)) {
743 entry->size_in_bits = payload_type->size_in_bits;743 entry->size_in_bits = payload_type->size_in_bits;
744 entry->abi_size = payload_type->abi_size;744 entry->abi_size = payload_type->abi_size;
745 entry->abi_align = payload_type->abi_align;745 entry->abi_align = payload_type->abi_align;
...@@ -856,13 +856,13 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {...@@ -856,13 +856,13 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
856 entry->data.structure.requires_comptime = true;856 entry->data.structure.requires_comptime = true;
857 }857 }
858858
859 if (!type_has_bits(ptr_type)) {859 if (!type_has_bits(g, ptr_type)) {
860 entry->data.structure.gen_field_count = 1;860 entry->data.structure.gen_field_count = 1;
861 entry->data.structure.fields[slice_ptr_index]->gen_index = SIZE_MAX;861 entry->data.structure.fields[slice_ptr_index]->gen_index = SIZE_MAX;
862 entry->data.structure.fields[slice_len_index]->gen_index = 0;862 entry->data.structure.fields[slice_len_index]->gen_index = 0;
863 }863 }
864864
865 if (type_has_bits(ptr_type)) {865 if (type_has_bits(g, ptr_type)) {
866 entry->size_in_bits = ptr_type->size_in_bits + g->builtin_types.entry_usize->size_in_bits;866 entry->size_in_bits = ptr_type->size_in_bits + g->builtin_types.entry_usize->size_in_bits;
867 entry->abi_size = ptr_type->abi_size + g->builtin_types.entry_usize->abi_size;867 entry->abi_size = ptr_type->abi_size + g->builtin_types.entry_usize->abi_size;
868 entry->abi_align = ptr_type->abi_align;868 entry->abi_align = ptr_type->abi_align;
...@@ -969,12 +969,12 @@ ZigType *get_stack_trace_type(CodeGen *g) {...@@ -969,12 +969,12 @@ ZigType *get_stack_trace_type(CodeGen *g) {
969969
970bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id) {970bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id) {
971 if (fn_type_id->cc == CallingConventionUnspecified) {971 if (fn_type_id->cc == CallingConventionUnspecified) {
972 return handle_is_ptr(fn_type_id->return_type);972 return handle_is_ptr(g, fn_type_id->return_type);
973 }973 }
974 if (fn_type_id->cc != CallingConventionC) {974 if (fn_type_id->cc != CallingConventionC) {
975 return false;975 return false;
976 }976 }
977 if (type_is_c_abi_int(g, fn_type_id->return_type)) {977 if (type_is_c_abi_int_bail(g, fn_type_id->return_type)) {
978 return false;978 return false;
979 }979 }
980 if (g->zig_target->arch == ZigLLVM_x86 ||980 if (g->zig_target->arch == ZigLLVM_x86 ||
...@@ -1650,15 +1650,16 @@ static Error emit_error_unless_type_allowed_in_packed_container(CodeGen *g, ZigT...@@ -1650,15 +1650,16 @@ static Error emit_error_unless_type_allowed_in_packed_container(CodeGen *g, ZigT
1650 return ErrorSemanticAnalyzeFail;1650 return ErrorSemanticAnalyzeFail;
1651 }1651 }
1652 zig_unreachable();1652 zig_unreachable();
1653 case ZigTypeIdOptional:1653 case ZigTypeIdOptional: {
1654 if (get_codegen_ptr_type(type_entry) != nullptr) {1654 ZigType *ptr_type;
1655 return ErrorNone;1655 if ((err = get_codegen_ptr_type(g, type_entry, &ptr_type))) return err;
1656 } else {1656 if (ptr_type != nullptr) return ErrorNone;
1657 add_node_error(g, source_node,1657
1658 buf_sprintf("type '%s' not allowed in packed %s; no guaranteed in-memory representation",1658 add_node_error(g, source_node,
1659 buf_ptr(&type_entry->name), container_name));1659 buf_sprintf("type '%s' not allowed in packed %s; no guaranteed in-memory representation",
1660 return ErrorSemanticAnalyzeFail;1660 buf_ptr(&type_entry->name), container_name));
1661 }1661 return ErrorSemanticAnalyzeFail;
1662 }
1662 case ZigTypeIdEnum: {1663 case ZigTypeIdEnum: {
1663 AstNode *decl_node = type_entry->data.enumeration.decl_node;1664 AstNode *decl_node = type_entry->data.enumeration.decl_node;
1664 if (decl_node->data.container_decl.init_arg_expr != nullptr) {1665 if (decl_node->data.container_decl.init_arg_expr != nullptr) {
...@@ -1737,7 +1738,7 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {...@@ -1737,7 +1738,7 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {
1737 case ZigTypeIdPointer:1738 case ZigTypeIdPointer:
1738 if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))1739 if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))
1739 return err;1740 return err;
1740 if (!type_has_bits(type_entry)) {1741 if (!type_has_bits(g, type_entry)) {
1741 *result = false;1742 *result = false;
1742 return ErrorNone;1743 return ErrorNone;
1743 }1744 }
...@@ -1753,7 +1754,7 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {...@@ -1753,7 +1754,7 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {
1753 *result = false;1754 *result = false;
1754 return ErrorNone;1755 return ErrorNone;
1755 }1756 }
1756 if (!type_is_nonnull_ptr(child_type)) {1757 if (!type_is_nonnull_ptr(g, child_type)) {
1757 *result = false;1758 *result = false;
1758 return ErrorNone;1759 return ErrorNone;
1759 }1760 }
...@@ -1848,7 +1849,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1848,7 +1849,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1848 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {1849 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
1849 if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))1850 if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))
1850 return g->builtin_types.entry_invalid;1851 return g->builtin_types.entry_invalid;
1851 if (!type_has_bits(type_entry)) {1852 if (!type_has_bits(g, type_entry)) {
1852 add_node_error(g, param_node->data.param_decl.type,1853 add_node_error(g, param_node->data.param_decl.type,
1853 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",1854 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",
1854 buf_ptr(&type_entry->name), calling_convention_name(fn_type_id.cc)));1855 buf_ptr(&type_entry->name), calling_convention_name(fn_type_id.cc)));
...@@ -2082,7 +2083,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel...@@ -2082,7 +2083,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel
2082 field->src_index = i;2083 field->src_index = i;
2083 field->align = fields[i].align;2084 field->align = fields[i].align;
20842085
2085 if (type_has_bits(field->type_entry)) {2086 if (type_has_bits(g, field->type_entry)) {
2086 assert(type_is_resolved(field->type_entry, ResolveStatusSizeKnown));2087 assert(type_is_resolved(field->type_entry, ResolveStatusSizeKnown));
2087 unsigned field_abi_align = max(field->align, field->type_entry->abi_align);2088 unsigned field_abi_align = max(field->align, field->type_entry->abi_align);
2088 if (field_abi_align > abi_align) {2089 if (field_abi_align > abi_align) {
...@@ -2097,7 +2098,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel...@@ -2097,7 +2098,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel
2097 size_t next_offset = 0;2098 size_t next_offset = 0;
2098 for (size_t i = 0; i < field_count; i += 1) {2099 for (size_t i = 0; i < field_count; i += 1) {
2099 TypeStructField *field = struct_type->data.structure.fields[i];2100 TypeStructField *field = struct_type->data.structure.fields[i];
2100 if (!type_has_bits(field->type_entry))2101 if (!type_has_bits(g, field->type_entry))
2101 continue;2102 continue;
21022103
2103 field->offset = next_offset;2104 field->offset = next_offset;
...@@ -2105,7 +2106,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel...@@ -2105,7 +2106,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel
2105 // find the next non-zero-byte field for offset calculations2106 // find the next non-zero-byte field for offset calculations
2106 size_t next_src_field_index = i + 1;2107 size_t next_src_field_index = i + 1;
2107 for (; next_src_field_index < field_count; next_src_field_index += 1) {2108 for (; next_src_field_index < field_count; next_src_field_index += 1) {
2108 if (type_has_bits(struct_type->data.structure.fields[next_src_field_index]->type_entry))2109 if (type_has_bits(g, struct_type->data.structure.fields[next_src_field_index]->type_entry))
2109 break;2110 break;
2110 }2111 }
2111 size_t next_abi_align;2112 size_t next_abi_align;
...@@ -2402,7 +2403,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {...@@ -2402,7 +2403,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {
2402 union_type->data.unionation.most_aligned_union_member = most_aligned_union_member;2403 union_type->data.unionation.most_aligned_union_member = most_aligned_union_member;
24032404
2404 ZigType *tag_type = union_type->data.unionation.tag_type;2405 ZigType *tag_type = union_type->data.unionation.tag_type;
2405 if (tag_type != nullptr && type_has_bits(tag_type)) {2406 if (tag_type != nullptr && type_has_bits(g, tag_type)) {
2406 if ((err = type_resolve(g, tag_type, ResolveStatusAlignmentKnown))) {2407 if ((err = type_resolve(g, tag_type, ResolveStatusAlignmentKnown))) {
2407 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2408 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2408 return ErrorSemanticAnalyzeFail;2409 return ErrorSemanticAnalyzeFail;
...@@ -2504,7 +2505,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -2504,7 +2505,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2504 if (type_is_invalid(union_type))2505 if (type_is_invalid(union_type))
2505 return ErrorSemanticAnalyzeFail;2506 return ErrorSemanticAnalyzeFail;
25062507
2507 if (!type_has_bits(field_type))2508 if (!type_has_bits(g, field_type))
2508 continue;2509 continue;
25092510
2510 union_abi_size = max(union_abi_size, field_type->abi_size);2511 union_abi_size = max(union_abi_size, field_type->abi_size);
...@@ -2523,7 +2524,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -2523,7 +2524,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2523 union_type->data.unionation.union_abi_size = union_abi_size;2524 union_type->data.unionation.union_abi_size = union_abi_size;
25242525
2525 ZigType *tag_type = union_type->data.unionation.tag_type;2526 ZigType *tag_type = union_type->data.unionation.tag_type;
2526 if (tag_type != nullptr && type_has_bits(tag_type)) {2527 if (tag_type != nullptr && type_has_bits(g, tag_type)) {
2527 if ((err = type_resolve(g, tag_type, ResolveStatusSizeKnown))) {2528 if ((err = type_resolve(g, tag_type, ResolveStatusSizeKnown))) {
2528 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2529 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2529 return ErrorSemanticAnalyzeFail;2530 return ErrorSemanticAnalyzeFail;
...@@ -2998,7 +2999,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {...@@ -2998,7 +2999,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {
2998 }2999 }
2999 }3000 }
30003001
3001 if (!type_has_bits(struct_type)) {3002 if (!type_has_bits(g, struct_type)) {
3002 assert(struct_type->abi_align == 0);3003 assert(struct_type->abi_align == 0);
3003 }3004 }
30043005
...@@ -4416,15 +4417,50 @@ ZigType *get_src_ptr_type(ZigType *type) {...@@ -4416,15 +4417,50 @@ ZigType *get_src_ptr_type(ZigType *type) {
4416 return nullptr;4417 return nullptr;
4417}4418}
44184419
4419ZigType *get_codegen_ptr_type(ZigType *type) {4420Error get_codegen_ptr_type(CodeGen *g, ZigType *type, ZigType **result) {
4421 Error err;
4422
4420 ZigType *ty = get_src_ptr_type(type);4423 ZigType *ty = get_src_ptr_type(type);
4421 if (ty == nullptr || !type_has_bits(ty))4424 if (ty == nullptr) {
4422 return nullptr;4425 *result = nullptr;
4423 return ty;4426 return ErrorNone;
4427 }
4428
4429 bool has_bits;
4430 if ((err = type_has_bits2(g, ty, &has_bits))) return err;
4431 if (!has_bits) {
4432 *result = nullptr;
4433 return ErrorNone;
4434 }
4435
4436 *result = ty;
4437 return ErrorNone;
4424}4438}
44254439
4426bool type_is_nonnull_ptr(ZigType *type) {4440ZigType *get_codegen_ptr_type_bail(CodeGen *g, ZigType *type) {
4427 return get_codegen_ptr_type(type) == type && !ptr_allows_addr_zero(type);4441 Error err;
4442 ZigType *result;
4443 if ((err = get_codegen_ptr_type(g, type, &result))) {
4444 codegen_report_errors_and_exit(g);
4445 }
4446 return result;
4447}
4448
4449bool type_is_nonnull_ptr(CodeGen *g, ZigType *type) {
4450 Error err;
4451 bool result;
4452 if ((err = type_is_nonnull_ptr2(g, type, &result))) {
4453 codegen_report_errors_and_exit(g);
4454 }
4455 return result;
4456}
4457
4458Error type_is_nonnull_ptr2(CodeGen *g, ZigType *type, bool *result) {
4459 Error err;
4460 ZigType *ptr_type;
4461 if ((err = get_codegen_ptr_type(g, type, &ptr_type))) return err;
4462 *result = ptr_type == type && !ptr_allows_addr_zero(type);
4463 return ErrorNone;
4428}4464}
44294465
4430static uint32_t get_async_frame_align_bytes(CodeGen *g) {4466static uint32_t get_async_frame_align_bytes(CodeGen *g) {
...@@ -4499,8 +4535,12 @@ static Error define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {...@@ -4499,8 +4535,12 @@ static Error define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
4499 }4535 }
45004536
4501 bool is_noalias = param_info->is_noalias;4537 bool is_noalias = param_info->is_noalias;
4502 if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) {4538 if (is_noalias) {
4503 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));4539 ZigType *ptr_type;
4540 if ((err = get_codegen_ptr_type(g, param_type, &ptr_type))) return err;
4541 if (ptr_type == nullptr) {
4542 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
4543 }
4504 }4544 }
45054545
4506 ZigVar *var = add_variable(g, param_decl_node, fn_table_entry->child_scope,4546 ZigVar *var = add_variable(g, param_decl_node, fn_table_entry->child_scope,
...@@ -4509,7 +4549,7 @@ static Error define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {...@@ -4509,7 +4549,7 @@ static Error define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
4509 fn_table_entry->child_scope = var->child_scope;4549 fn_table_entry->child_scope = var->child_scope;
4510 var->shadowable = var->shadowable || is_var_args;4550 var->shadowable = var->shadowable || is_var_args;
45114551
4512 if (type_has_bits(param_type)) {4552 if (type_has_bits(g, param_type)) {
4513 fn_table_entry->variable_list.append(var);4553 fn_table_entry->variable_list.append(var);
4514 }4554 }
4515 }4555 }
...@@ -5027,15 +5067,35 @@ ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {...@@ -5027,15 +5067,35 @@ ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
5027 return new_entry;5067 return new_entry;
5028}5068}
50295069
5030bool is_valid_vector_elem_type(ZigType *elem_type) {5070Error is_valid_vector_elem_type(CodeGen *g, ZigType *elem_type, bool *result) {
5031 return elem_type->id == ZigTypeIdInt ||5071 if (elem_type->id == ZigTypeIdInt ||
5032 elem_type->id == ZigTypeIdFloat ||5072 elem_type->id == ZigTypeIdFloat ||
5033 elem_type->id == ZigTypeIdBool ||5073 elem_type->id == ZigTypeIdBool)
5034 get_codegen_ptr_type(elem_type) != nullptr;5074 {
5075 *result = true;
5076 return ErrorNone;
5077 }
5078
5079 Error err;
5080 ZigType *ptr_type;
5081 if ((err = get_codegen_ptr_type(g, elem_type, &ptr_type))) return err;
5082 if (ptr_type != nullptr) {
5083 *result = true;
5084 return ErrorNone;
5085 }
5086
5087 *result = false;
5088 return ErrorNone;
5035}5089}
50365090
5037ZigType *get_vector_type(CodeGen *g, uint32_t len, ZigType *elem_type) {5091ZigType *get_vector_type(CodeGen *g, uint32_t len, ZigType *elem_type) {
5038 assert(is_valid_vector_elem_type(elem_type));5092 Error err;
5093
5094 bool valid_vector_elem;
5095 if ((err = is_valid_vector_elem_type(g, elem_type, &valid_vector_elem))) {
5096 codegen_report_errors_and_exit(g);
5097 }
5098 assert(valid_vector_elem);
50395099
5040 TypeId type_id = {};5100 TypeId type_id = {};
5041 type_id.id = ZigTypeIdVector;5101 type_id.id = ZigTypeIdVector;
...@@ -5049,7 +5109,7 @@ ZigType *get_vector_type(CodeGen *g, uint32_t len, ZigType *elem_type) {...@@ -5049,7 +5109,7 @@ ZigType *get_vector_type(CodeGen *g, uint32_t len, ZigType *elem_type) {
5049 }5109 }
50505110
5051 ZigType *entry = new_type_table_entry(ZigTypeIdVector);5111 ZigType *entry = new_type_table_entry(ZigTypeIdVector);
5052 if ((len != 0) && type_has_bits(elem_type)) {5112 if ((len != 0) && type_has_bits(g, elem_type)) {
5053 // Vectors can only be ints, floats, bools, or pointers. ints (inc. bools) and floats have trivially resolvable5113 // Vectors can only be ints, floats, bools, or pointers. ints (inc. bools) and floats have trivially resolvable
5054 // llvm type refs. pointers we will use usize instead.5114 // llvm type refs. pointers we will use usize instead.
5055 LLVMTypeRef example_vector_llvm_type;5115 LLVMTypeRef example_vector_llvm_type;
...@@ -5081,7 +5141,7 @@ ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type) {...@@ -5081,7 +5141,7 @@ ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type) {
5081 return *get_c_int_type_ptr(g, c_int_type);5141 return *get_c_int_type_ptr(g, c_int_type);
5082}5142}
50835143
5084bool handle_is_ptr(ZigType *type_entry) {5144bool handle_is_ptr(CodeGen *g, ZigType *type_entry) {
5085 switch (type_entry->id) {5145 switch (type_entry->id) {
5086 case ZigTypeIdInvalid:5146 case ZigTypeIdInvalid:
5087 case ZigTypeIdMetaType:5147 case ZigTypeIdMetaType:
...@@ -5108,15 +5168,15 @@ bool handle_is_ptr(ZigType *type_entry) {...@@ -5108,15 +5168,15 @@ bool handle_is_ptr(ZigType *type_entry) {
5108 case ZigTypeIdArray:5168 case ZigTypeIdArray:
5109 case ZigTypeIdStruct:5169 case ZigTypeIdStruct:
5110 case ZigTypeIdFnFrame:5170 case ZigTypeIdFnFrame:
5111 return type_has_bits(type_entry);5171 return type_has_bits(g, type_entry);
5112 case ZigTypeIdErrorUnion:5172 case ZigTypeIdErrorUnion:
5113 return type_has_bits(type_entry->data.error_union.payload_type);5173 return type_has_bits(g, type_entry->data.error_union.payload_type);
5114 case ZigTypeIdOptional:5174 case ZigTypeIdOptional:
5115 return type_has_bits(type_entry->data.maybe.child_type) &&5175 return type_has_bits(g, type_entry->data.maybe.child_type) &&
5116 !type_is_nonnull_ptr(type_entry->data.maybe.child_type) &&5176 !type_is_nonnull_ptr(g, type_entry->data.maybe.child_type) &&
5117 type_entry->data.maybe.child_type->id != ZigTypeIdErrorSet;5177 type_entry->data.maybe.child_type->id != ZigTypeIdErrorSet;
5118 case ZigTypeIdUnion:5178 case ZigTypeIdUnion:
5119 return type_has_bits(type_entry) && type_entry->data.unionation.gen_field_count != 0;5179 return type_has_bits(g, type_entry) && type_entry->data.unionation.gen_field_count != 0;
51205180
5121 }5181 }
5122 zig_unreachable();5182 zig_unreachable();
...@@ -5329,7 +5389,7 @@ static uint32_t hash_const_val(ZigValue *const_val) {...@@ -5329,7 +5389,7 @@ static uint32_t hash_const_val(ZigValue *const_val) {
5329 // TODO better hashing algorithm5389 // TODO better hashing algorithm
5330 return 2709806591;5390 return 2709806591;
5331 case ZigTypeIdOptional:5391 case ZigTypeIdOptional:
5332 if (get_codegen_ptr_type(const_val->type) != nullptr) {5392 if (get_src_ptr_type(const_val->type) != nullptr) {
5333 return hash_const_val_ptr(const_val) * 1992916303;5393 return hash_const_val_ptr(const_val) * 1992916303;
5334 } else if (const_val->type->data.maybe.child_type->id == ZigTypeIdErrorSet) {5394 } else if (const_val->type->data.maybe.child_type->id == ZigTypeIdErrorSet) {
5335 return hash_const_val_error_set(const_val) * 3147031929;5395 return hash_const_val_error_set(const_val) * 3147031929;
...@@ -5455,7 +5515,7 @@ static bool can_mutate_comptime_var_state(ZigValue *value) {...@@ -5455,7 +5515,7 @@ static bool can_mutate_comptime_var_state(ZigValue *value) {
5455 return false;5515 return false;
54565516
5457 case ZigTypeIdOptional:5517 case ZigTypeIdOptional:
5458 if (get_codegen_ptr_type(value->type) != nullptr)5518 if (get_src_ptr_type(value->type) != nullptr)
5459 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;5519 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;
5460 if (value->data.x_optional == nullptr)5520 if (value->data.x_optional == nullptr)
5461 return false;5521 return false;
...@@ -5593,11 +5653,13 @@ bool fn_eval_eql(Scope *a, Scope *b) {...@@ -5593,11 +5653,13 @@ bool fn_eval_eql(Scope *a, Scope *b) {
5593}5653}
55945654
5595// Deprecated. Use type_has_bits2.5655// Deprecated. Use type_has_bits2.
5596bool type_has_bits(ZigType *type_entry) {5656bool type_has_bits(CodeGen *g, ZigType *type_entry) {
5597 assert(type_entry != nullptr);5657 Error err;
5598 assert(!type_is_invalid(type_entry));5658 bool result;
5599 assert(type_is_resolved(type_entry, ResolveStatusZeroBitsKnown));5659 if ((err = type_has_bits2(g, type_entry, &result))) {
5600 return type_entry->abi_size != 0;5660 codegen_report_errors_and_exit(g);
5661 }
5662 return result;
5601}5663}
56025664
5603// Whether the type has bits at runtime.5665// Whether the type has bits at runtime.
...@@ -5687,7 +5749,7 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {...@@ -5687,7 +5749,7 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
5687 case ZigTypeIdEnum:5749 case ZigTypeIdEnum:
5688 case ZigTypeIdInt:5750 case ZigTypeIdInt:
5689 case ZigTypeIdVector:5751 case ZigTypeIdVector:
5690 return type_has_bits(type_entry) ? OnePossibleValueNo : OnePossibleValueYes;5752 return type_has_bits(g, type_entry) ? OnePossibleValueNo : OnePossibleValueYes;
5691 case ZigTypeIdPointer: {5753 case ZigTypeIdPointer: {
5692 ZigType *elem_type = type_entry->data.pointer.child_type;5754 ZigType *elem_type = type_entry->data.pointer.child_type;
5693 // If the recursive function call asks, then we are not one possible value.5755 // If the recursive function call asks, then we are not one possible value.
...@@ -6365,7 +6427,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6365,7 +6427,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6365 }6427 }
6366 if (await->base.base.ref_count == 0)6428 if (await->base.base.ref_count == 0)
6367 continue;6429 continue;
6368 if (!type_has_bits(await->base.value->type))6430 if (!type_has_bits(g, await->base.value->type))
6369 continue;6431 continue;
6370 await->result_loc = ir_create_alloca(g, await->base.base.scope, await->base.base.source_node, fn,6432 await->result_loc = ir_create_alloca(g, await->base.base.scope, await->base.base.source_node, fn,
6371 await->base.value->type, "");6433 await->base.value->type, "");
...@@ -6406,7 +6468,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6406,7 +6468,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6406 continue;6468 continue;
6407 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))6469 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))
6408 return ErrorSemanticAnalyzeFail;6470 return ErrorSemanticAnalyzeFail;
6409 if (!type_has_bits(instruction->value->type))6471 if (!type_has_bits(g, instruction->value->type))
6410 continue;6472 continue;
6411 if (scope_needs_spill(instruction->base.scope)) {6473 if (scope_needs_spill(instruction->base.scope)) {
6412 instruction->spill = ir_create_alloca(g, instruction->base.scope, instruction->base.source_node,6474 instruction->spill = ir_create_alloca(g, instruction->base.scope, instruction->base.source_node,
...@@ -6465,7 +6527,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6465,7 +6527,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6465 ZigType *ptr_type = instruction->base.value->type;6527 ZigType *ptr_type = instruction->base.value->type;
6466 assert(ptr_type->id == ZigTypeIdPointer);6528 assert(ptr_type->id == ZigTypeIdPointer);
6467 ZigType *child_type = resolve_type_isf(ptr_type->data.pointer.child_type);6529 ZigType *child_type = resolve_type_isf(ptr_type->data.pointer.child_type);
6468 if (!type_has_bits(child_type))6530 if (!type_has_bits(g, child_type))
6469 continue;6531 continue;
6470 if (instruction->base.base.ref_count == 0)6532 if (instruction->base.base.ref_count == 0)
6471 continue;6533 continue;
...@@ -6763,7 +6825,7 @@ bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b) {...@@ -6763,7 +6825,7 @@ bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b) {
6763 if (bigint_cmp(&union1->tag, &union2->tag) == CmpEQ) {6825 if (bigint_cmp(&union1->tag, &union2->tag) == CmpEQ) {
6764 TypeUnionField *field = find_union_field_by_tag(a->type, &union1->tag);6826 TypeUnionField *field = find_union_field_by_tag(a->type, &union1->tag);
6765 assert(field != nullptr);6827 assert(field != nullptr);
6766 if (!type_has_bits(field->type_entry))6828 if (!type_has_bits(g, field->type_entry))
6767 return true;6829 return true;
6768 assert(find_union_field_by_tag(a->type, &union2->tag) != nullptr);6830 assert(find_union_field_by_tag(a->type, &union2->tag) != nullptr);
6769 return const_values_equal(g, union1->payload, union2->payload);6831 return const_values_equal(g, union1->payload, union2->payload);
...@@ -6826,7 +6888,7 @@ bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b) {...@@ -6826,7 +6888,7 @@ bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b) {
6826 case ZigTypeIdNull:6888 case ZigTypeIdNull:
6827 zig_panic("TODO");6889 zig_panic("TODO");
6828 case ZigTypeIdOptional:6890 case ZigTypeIdOptional:
6829 if (get_codegen_ptr_type(a->type) != nullptr)6891 if (get_src_ptr_type(a->type) != nullptr)
6830 return const_values_equal_ptr(a, b);6892 return const_values_equal_ptr(a, b);
6831 if (a->data.x_optional == nullptr || b->data.x_optional == nullptr) {6893 if (a->data.x_optional == nullptr || b->data.x_optional == nullptr) {
6832 return (a->data.x_optional == nullptr && b->data.x_optional == nullptr);6894 return (a->data.x_optional == nullptr && b->data.x_optional == nullptr);
...@@ -7097,7 +7159,7 @@ void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val) {...@@ -7097,7 +7159,7 @@ void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val) {
7097 }7159 }
7098 case ZigTypeIdOptional:7160 case ZigTypeIdOptional:
7099 {7161 {
7100 if (get_codegen_ptr_type(const_val->type) != nullptr)7162 if (get_src_ptr_type(const_val->type) != nullptr)
7101 return render_const_val_ptr(g, buf, const_val, type_entry->data.maybe.child_type);7163 return render_const_val_ptr(g, buf, const_val, type_entry->data.maybe.child_type);
7102 if (type_entry->data.maybe.child_type->id == ZigTypeIdErrorSet)7164 if (type_entry->data.maybe.child_type->id == ZigTypeIdErrorSet)
7103 return render_const_val_err_set(g, buf, const_val, type_entry->data.maybe.child_type);7165 return render_const_val_err_set(g, buf, const_val, type_entry->data.maybe.child_type);
...@@ -7881,8 +7943,12 @@ static X64CABIClass type_system_V_abi_x86_64_class(CodeGen *g, ZigType *ty, size...@@ -7881,8 +7943,12 @@ static X64CABIClass type_system_V_abi_x86_64_class(CodeGen *g, ZigType *ty, size
7881}7943}
78827944
7883X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) {7945X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) {
7946 Error err;
7947
7884 const size_t ty_size = type_size(g, ty);7948 const size_t ty_size = type_size(g, ty);
7885 if (get_codegen_ptr_type(ty) != nullptr)7949 ZigType *ptr_type;
7950 if ((err = get_codegen_ptr_type(g, ty, &ptr_type))) return X64CABIClass_Unknown;
7951 if (ptr_type != nullptr)
7886 return X64CABIClass_INTEGER;7952 return X64CABIClass_INTEGER;
78877953
7888 if (g->zig_target->os == OsWindows || g->zig_target->os == OsUefi) {7954 if (g->zig_target->os == OsWindows || g->zig_target->os == OsUefi) {
...@@ -7898,14 +7964,32 @@ X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) {...@@ -7898,14 +7964,32 @@ X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) {
7898}7964}
78997965
7900// NOTE this does not depend on x86_647966// NOTE this does not depend on x86_64
7901bool type_is_c_abi_int(CodeGen *g, ZigType *ty) {7967Error type_is_c_abi_int(CodeGen *g, ZigType *ty, bool *result) {
7902 return (ty->id == ZigTypeIdInt ||7968 if (ty->id == ZigTypeIdInt ||
7903 ty->id == ZigTypeIdFloat ||7969 ty->id == ZigTypeIdFloat ||
7904 ty->id == ZigTypeIdBool ||7970 ty->id == ZigTypeIdBool ||
7905 ty->id == ZigTypeIdEnum ||7971 ty->id == ZigTypeIdEnum ||
7906 ty->id == ZigTypeIdVoid ||7972 ty->id == ZigTypeIdVoid ||
7907 ty->id == ZigTypeIdUnreachable ||7973 ty->id == ZigTypeIdUnreachable)
7908 get_codegen_ptr_type(ty) != nullptr);7974 {
7975 *result = true;
7976 return ErrorNone;
7977 }
7978
7979 Error err;
7980 ZigType *ptr_type;
7981 if ((err = get_codegen_ptr_type(g, ty, &ptr_type))) return err;
7982 *result = ptr_type != nullptr;
7983 return ErrorNone;
7984}
7985
7986bool type_is_c_abi_int_bail(CodeGen *g, ZigType *ty) {
7987 Error err;
7988 bool result;
7989 if ((err = type_is_c_abi_int(g, ty, &result)))
7990 codegen_report_errors_and_exit(g);
7991
7992 return result;
7909}7993}
79107994
7911uint32_t get_host_int_bytes(CodeGen *g, ZigType *struct_type, TypeStructField *field) {7995uint32_t get_host_int_bytes(CodeGen *g, ZigType *struct_type, TypeStructField *field) {
...@@ -8036,7 +8120,7 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa...@@ -8036,7 +8120,7 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa
8036 if (ResolveStatusLLVMFwdDecl >= wanted_resolve_status) return;8120 if (ResolveStatusLLVMFwdDecl >= wanted_resolve_status) return;
8037 }8121 }
80388122
8039 if (!type_has_bits(child_type)) {8123 if (!type_has_bits(g, child_type)) {
8040 LLVMTypeRef element_types[] = {8124 LLVMTypeRef element_types[] = {
8041 usize_llvm_type,8125 usize_llvm_type,
8042 };8126 };
...@@ -8145,7 +8229,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS...@@ -8145,7 +8229,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
8145 }8229 }
81468230
8147 if (struct_type->data.structure.resolve_status < ResolveStatusLLVMFwdDecl) {8231 if (struct_type->data.structure.resolve_status < ResolveStatusLLVMFwdDecl) {
8148 struct_type->llvm_type = type_has_bits(struct_type) ?8232 struct_type->llvm_type = type_has_bits(g, struct_type) ?
8149 LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&struct_type->name)) : LLVMVoidType();8233 LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&struct_type->name)) : LLVMVoidType();
8150 unsigned dwarf_kind = ZigLLVMTag_DW_structure_type();8234 unsigned dwarf_kind = ZigLLVMTag_DW_structure_type();
8151 struct_type->llvm_di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,8235 struct_type->llvm_di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,
...@@ -8175,7 +8259,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS...@@ -8175,7 +8259,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
8175 for (size_t i = 0; i < field_count; i += 1) {8259 for (size_t i = 0; i < field_count; i += 1) {
8176 TypeStructField *field = struct_type->data.structure.fields[i];8260 TypeStructField *field = struct_type->data.structure.fields[i];
8177 ZigType *field_type = field->type_entry;8261 ZigType *field_type = field->type_entry;
8178 if (!type_has_bits(field_type))8262 if (!type_has_bits(g, field_type))
8179 continue;8263 continue;
8180 (void)get_llvm_type(g, field_type);8264 (void)get_llvm_type(g, field_type);
8181 if (struct_type->data.structure.resolve_status >= wanted_resolve_status) return;8265 if (struct_type->data.structure.resolve_status >= wanted_resolve_status) return;
...@@ -8189,7 +8273,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS...@@ -8189,7 +8273,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
8189 for (size_t i = 0; i < field_count; i += 1) {8273 for (size_t i = 0; i < field_count; i += 1) {
8190 TypeStructField *field = struct_type->data.structure.fields[i];8274 TypeStructField *field = struct_type->data.structure.fields[i];
8191 ZigType *field_type = field->type_entry;8275 ZigType *field_type = field->type_entry;
8192 if (field->is_comptime || !type_has_bits(field_type))8276 if (field->is_comptime || !type_has_bits(g, field_type))
8193 continue;8277 continue;
8194 LLVMTypeRef field_llvm_type = get_llvm_type(g, field_type);8278 LLVMTypeRef field_llvm_type = get_llvm_type(g, field_type);
8195 size_t llvm_field_abi_align = LLVMABIAlignmentOfType(g->target_data_ref, field_llvm_type);8279 size_t llvm_field_abi_align = LLVMABIAlignmentOfType(g->target_data_ref, field_llvm_type);
...@@ -8200,7 +8284,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS...@@ -8200,7 +8284,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
8200 TypeStructField *field = struct_type->data.structure.fields[i];8284 TypeStructField *field = struct_type->data.structure.fields[i];
8201 ZigType *field_type = field->type_entry;8285 ZigType *field_type = field->type_entry;
82028286
8203 if (field->is_comptime || !type_has_bits(field_type)) {8287 if (field->is_comptime || !type_has_bits(g, field_type)) {
8204 field->gen_index = SIZE_MAX;8288 field->gen_index = SIZE_MAX;
8205 continue;8289 continue;
8206 }8290 }
...@@ -8247,7 +8331,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS...@@ -8247,7 +8331,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
8247 // find the next non-zero-byte field for offset calculations8331 // find the next non-zero-byte field for offset calculations
8248 size_t next_src_field_index = i + 1;8332 size_t next_src_field_index = i + 1;
8249 for (; next_src_field_index < field_count; next_src_field_index += 1) {8333 for (; next_src_field_index < field_count; next_src_field_index += 1) {
8250 if (type_has_bits(struct_type->data.structure.fields[next_src_field_index]->type_entry))8334 if (type_has_bits(g, struct_type->data.structure.fields[next_src_field_index]->type_entry))
8251 break;8335 break;
8252 }8336 }
8253 size_t next_abi_align;8337 size_t next_abi_align;
...@@ -8293,7 +8377,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS...@@ -8293,7 +8377,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
8293 gen_field_index += 1;8377 gen_field_index += 1;
8294 }8378 }
82958379
8296 if (type_has_bits(struct_type)) {8380 if (type_has_bits(g, struct_type)) {
8297 assert(struct_type->data.structure.gen_field_count == gen_field_index);8381 assert(struct_type->data.structure.gen_field_count == gen_field_index);
8298 LLVMStructSetBody(struct_type->llvm_type, element_types,8382 LLVMStructSetBody(struct_type->llvm_type, element_types,
8299 (unsigned)struct_type->data.structure.gen_field_count, packed);8383 (unsigned)struct_type->data.structure.gen_field_count, packed);
...@@ -8405,7 +8489,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatu...@@ -8405,7 +8489,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatu
8405 ZigType *import = get_scope_import(scope);8489 ZigType *import = get_scope_import(scope);
8406 AstNode *decl_node = enum_type->data.enumeration.decl_node;8490 AstNode *decl_node = enum_type->data.enumeration.decl_node;
84078491
8408 if (!type_has_bits(enum_type)) {8492 if (!type_has_bits(g, enum_type)) {
8409 enum_type->llvm_type = g->builtin_types.entry_void->llvm_type;8493 enum_type->llvm_type = g->builtin_types.entry_void->llvm_type;
8410 enum_type->llvm_di_type = make_empty_namespace_llvm_di_type(g, import, buf_ptr(&enum_type->name),8494 enum_type->llvm_di_type = make_empty_namespace_llvm_di_type(g, import, buf_ptr(&enum_type->name),
8411 decl_node);8495 decl_node);
...@@ -8487,7 +8571,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta...@@ -8487,7 +8571,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
8487 uint32_t field_count = union_type->data.unionation.src_field_count;8571 uint32_t field_count = union_type->data.unionation.src_field_count;
8488 for (uint32_t i = 0; i < field_count; i += 1) {8572 for (uint32_t i = 0; i < field_count; i += 1) {
8489 TypeUnionField *union_field = &union_type->data.unionation.fields[i];8573 TypeUnionField *union_field = &union_type->data.unionation.fields[i];
8490 if (!type_has_bits(union_field->type_entry))8574 if (!type_has_bits(g, union_field->type_entry))
8491 continue;8575 continue;
84928576
8493 ZigLLVMDIType *field_di_type = get_llvm_di_type(g, union_field->type_entry);8577 ZigLLVMDIType *field_di_type = get_llvm_di_type(g, union_field->type_entry);
...@@ -8506,7 +8590,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta...@@ -8506,7 +8590,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
85068590
8507 }8591 }
85088592
8509 if (tag_type == nullptr || !type_has_bits(tag_type)) {8593 if (tag_type == nullptr || !type_has_bits(g, tag_type)) {
8510 assert(most_aligned_union_member != nullptr);8594 assert(most_aligned_union_member != nullptr);
85118595
8512 size_t padding_bytes = union_type->data.unionation.union_abi_size - most_aligned_union_member->type_entry->abi_size;8596 size_t padding_bytes = union_type->data.unionation.union_abi_size - most_aligned_union_member->type_entry->abi_size;
...@@ -8616,7 +8700,7 @@ static void resolve_llvm_types_pointer(CodeGen *g, ZigType *type, ResolveStatus...@@ -8616,7 +8700,7 @@ static void resolve_llvm_types_pointer(CodeGen *g, ZigType *type, ResolveStatus
8616 if (resolve_pointer_zero_bits(g, type) != ErrorNone)8700 if (resolve_pointer_zero_bits(g, type) != ErrorNone)
8617 zig_unreachable();8701 zig_unreachable();
86188702
8619 if (!type_has_bits(type)) {8703 if (!type_has_bits(g, type)) {
8620 type->llvm_type = g->builtin_types.entry_void->llvm_type;8704 type->llvm_type = g->builtin_types.entry_void->llvm_type;
8621 type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;8705 type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;
8622 return;8706 return;
...@@ -8669,7 +8753,7 @@ static void resolve_llvm_types_pointer(CodeGen *g, ZigType *type, ResolveStatus...@@ -8669,7 +8753,7 @@ static void resolve_llvm_types_pointer(CodeGen *g, ZigType *type, ResolveStatus
8669static void resolve_llvm_types_integer(CodeGen *g, ZigType *type) {8753static void resolve_llvm_types_integer(CodeGen *g, ZigType *type) {
8670 if (type->llvm_di_type != nullptr) return;8754 if (type->llvm_di_type != nullptr) return;
86718755
8672 if (!type_has_bits(type)) {8756 if (!type_has_bits(g, type)) {
8673 type->llvm_type = g->builtin_types.entry_void->llvm_type;8757 type->llvm_type = g->builtin_types.entry_void->llvm_type;
8674 type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;8758 type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;
8675 return;8759 return;
...@@ -8705,14 +8789,14 @@ static void resolve_llvm_types_optional(CodeGen *g, ZigType *type, ResolveStatus...@@ -8705,14 +8789,14 @@ static void resolve_llvm_types_optional(CodeGen *g, ZigType *type, ResolveStatus
8705 ZigLLVMDIType *bool_llvm_di_type = get_llvm_di_type(g, g->builtin_types.entry_bool);8789 ZigLLVMDIType *bool_llvm_di_type = get_llvm_di_type(g, g->builtin_types.entry_bool);
87068790
8707 ZigType *child_type = type->data.maybe.child_type;8791 ZigType *child_type = type->data.maybe.child_type;
8708 if (!type_has_bits(child_type)) {8792 if (!type_has_bits(g, child_type)) {
8709 type->llvm_type = bool_llvm_type;8793 type->llvm_type = bool_llvm_type;
8710 type->llvm_di_type = bool_llvm_di_type;8794 type->llvm_di_type = bool_llvm_di_type;
8711 type->data.maybe.resolve_status = ResolveStatusLLVMFull;8795 type->data.maybe.resolve_status = ResolveStatusLLVMFull;
8712 return;8796 return;
8713 }8797 }
87148798
8715 if (type_is_nonnull_ptr(child_type) || child_type->id == ZigTypeIdErrorSet) {8799 if (type_is_nonnull_ptr(g, child_type) || child_type->id == ZigTypeIdErrorSet) {
8716 type->llvm_type = get_llvm_type(g, child_type);8800 type->llvm_type = get_llvm_type(g, child_type);
8717 type->llvm_di_type = get_llvm_di_type(g, child_type);8801 type->llvm_di_type = get_llvm_di_type(g, child_type);
8718 type->data.maybe.resolve_status = ResolveStatusLLVMFull;8802 type->data.maybe.resolve_status = ResolveStatusLLVMFull;
...@@ -8778,11 +8862,11 @@ static void resolve_llvm_types_error_union(CodeGen *g, ZigType *type) {...@@ -8778,11 +8862,11 @@ static void resolve_llvm_types_error_union(CodeGen *g, ZigType *type) {
8778 ZigType *payload_type = type->data.error_union.payload_type;8862 ZigType *payload_type = type->data.error_union.payload_type;
8779 ZigType *err_set_type = type->data.error_union.err_set_type;8863 ZigType *err_set_type = type->data.error_union.err_set_type;
87808864
8781 if (!type_has_bits(payload_type)) {8865 if (!type_has_bits(g, payload_type)) {
8782 assert(type_has_bits(err_set_type));8866 assert(type_has_bits(g, err_set_type));
8783 type->llvm_type = get_llvm_type(g, err_set_type);8867 type->llvm_type = get_llvm_type(g, err_set_type);
8784 type->llvm_di_type = get_llvm_di_type(g, err_set_type);8868 type->llvm_di_type = get_llvm_di_type(g, err_set_type);
8785 } else if (!type_has_bits(err_set_type)) {8869 } else if (!type_has_bits(g, err_set_type)) {
8786 type->llvm_type = get_llvm_type(g, payload_type);8870 type->llvm_type = get_llvm_type(g, payload_type);
8787 type->llvm_di_type = get_llvm_di_type(g, payload_type);8871 type->llvm_di_type = get_llvm_di_type(g, payload_type);
8788 } else {8872 } else {
...@@ -8852,7 +8936,7 @@ static void resolve_llvm_types_error_union(CodeGen *g, ZigType *type) {...@@ -8852,7 +8936,7 @@ static void resolve_llvm_types_error_union(CodeGen *g, ZigType *type) {
8852static void resolve_llvm_types_array(CodeGen *g, ZigType *type) {8936static void resolve_llvm_types_array(CodeGen *g, ZigType *type) {
8853 if (type->llvm_di_type != nullptr) return;8937 if (type->llvm_di_type != nullptr) return;
88548938
8855 if (!type_has_bits(type)) {8939 if (!type_has_bits(g, type)) {
8856 type->llvm_type = g->builtin_types.entry_void->llvm_type;8940 type->llvm_type = g->builtin_types.entry_void->llvm_type;
8857 type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;8941 type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;
8858 return;8942 return;
...@@ -8893,7 +8977,7 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {...@@ -8893,7 +8977,7 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {
8893 if (is_async) {8977 if (is_async) {
8894 gen_return_type = g->builtin_types.entry_void;8978 gen_return_type = g->builtin_types.entry_void;
8895 param_di_types.append(nullptr);8979 param_di_types.append(nullptr);
8896 } else if (!type_has_bits(fn_type_id->return_type)) {8980 } else if (!type_has_bits(g, fn_type_id->return_type)) {
8897 gen_return_type = g->builtin_types.entry_void;8981 gen_return_type = g->builtin_types.entry_void;
8898 param_di_types.append(nullptr);8982 param_di_types.append(nullptr);
8899 } else if (first_arg_return) {8983 } else if (first_arg_return) {
...@@ -8940,11 +9024,11 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {...@@ -8940,11 +9024,11 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {
8940 gen_param_info->src_index = i;9024 gen_param_info->src_index = i;
8941 gen_param_info->gen_index = SIZE_MAX;9025 gen_param_info->gen_index = SIZE_MAX;
89429026
8943 if (is_c_abi || !type_has_bits(type_entry))9027 if (is_c_abi || !type_has_bits(g, type_entry))
8944 continue;9028 continue;
89459029
8946 ZigType *gen_type;9030 ZigType *gen_type;
8947 if (handle_is_ptr(type_entry)) {9031 if (handle_is_ptr(g, type_entry)) {
8948 gen_type = get_pointer_to_type(g, type_entry, true);9032 gen_type = get_pointer_to_type(g, type_entry, true);
8949 gen_param_info->is_byval = true;9033 gen_param_info->is_byval = true;
8950 } else {9034 } else {
...@@ -9098,7 +9182,7 @@ static void resolve_llvm_types_any_frame(CodeGen *g, ZigType *any_frame_type, Re...@@ -9098,7 +9182,7 @@ static void resolve_llvm_types_any_frame(CodeGen *g, ZigType *any_frame_type, Re
9098 field_types.append(usize_type_ref); // resume_index9182 field_types.append(usize_type_ref); // resume_index
9099 field_types.append(usize_type_ref); // awaiter9183 field_types.append(usize_type_ref); // awaiter
91009184
9101 bool have_result_type = result_type != nullptr && type_has_bits(result_type);9185 bool have_result_type = result_type != nullptr && type_has_bits(g, result_type);
9102 if (have_result_type) {9186 if (have_result_type) {
9103 field_types.append(get_llvm_type(g, ptr_result_type)); // result_ptr_callee9187 field_types.append(get_llvm_type(g, ptr_result_type)); // result_ptr_callee
9104 field_types.append(get_llvm_type(g, ptr_result_type)); // result_ptr_awaiter9188 field_types.append(get_llvm_type(g, ptr_result_type)); // result_ptr_awaiter
...@@ -9379,7 +9463,7 @@ bool is_opt_err_set(ZigType *ty) {...@@ -9379,7 +9463,7 @@ bool is_opt_err_set(ZigType *ty) {
9379bool type_has_optional_repr(ZigType *ty) {9463bool type_has_optional_repr(ZigType *ty) {
9380 if (ty->id != ZigTypeIdOptional) {9464 if (ty->id != ZigTypeIdOptional) {
9381 return false;9465 return false;
9382 } else if (get_codegen_ptr_type(ty) != nullptr) {9466 } else if (get_src_ptr_type(ty) != nullptr) {
9383 return false;9467 return false;
9384 } else if (is_opt_err_set(ty)) {9468 } else if (is_opt_err_set(ty)) {
9385 return false;9469 return false;
...@@ -9471,6 +9555,58 @@ bool type_is_numeric(ZigType *ty) {...@@ -9471,6 +9555,58 @@ bool type_is_numeric(ZigType *ty) {
9471 zig_unreachable();9555 zig_unreachable();
9472}9556}
94739557
9558static void dump_value_indent_error_set(ZigValue *val, int indent) {
9559 fprintf(stderr, "<TODO dump value>\n");
9560}
9561
9562static void dump_value_indent(ZigValue *val, int indent);
9563
9564static void dump_value_indent_ptr(ZigValue *val, int indent) {
9565 switch (val->data.x_ptr.special) {
9566 case ConstPtrSpecialInvalid:
9567 fprintf(stderr, "<!invalid ptr!>\n");
9568 return;
9569 case ConstPtrSpecialNull:
9570 fprintf(stderr, "<null>\n");
9571 return;
9572 case ConstPtrSpecialRef:
9573 fprintf(stderr, "<ref\n");
9574 dump_value_indent(val->data.x_ptr.data.ref.pointee, indent + 1);
9575 break;
9576 case ConstPtrSpecialBaseStruct: {
9577 ZigValue *struct_val = val->data.x_ptr.data.base_struct.struct_val;
9578 size_t field_index = val->data.x_ptr.data.base_struct.field_index;
9579 fprintf(stderr, "<struct %p field %zu\n", struct_val, field_index);
9580 if (struct_val != nullptr) {
9581 ZigValue *field_val = struct_val->data.x_struct.fields[field_index];
9582 if (field_val != nullptr) {
9583 dump_value_indent(field_val, indent + 1);
9584 } else {
9585 for (int i = 0; i < indent; i += 1) {
9586 fprintf(stderr, " ");
9587 }
9588 fprintf(stderr, "(invalid null field)\n");
9589 }
9590 }
9591 break;
9592 }
9593 case ConstPtrSpecialBaseOptionalPayload: {
9594 ZigValue *optional_val = val->data.x_ptr.data.base_optional_payload.optional_val;
9595 fprintf(stderr, "<optional %p payload\n", optional_val);
9596 if (optional_val != nullptr) {
9597 dump_value_indent(optional_val, indent + 1);
9598 }
9599 break;
9600 }
9601 default:
9602 fprintf(stderr, "TODO dump more pointer things\n");
9603 }
9604 for (int i = 0; i < indent; i += 1) {
9605 fprintf(stderr, " ");
9606 }
9607 fprintf(stderr, ">\n");
9608}
9609
9474static void dump_value_indent(ZigValue *val, int indent) {9610static void dump_value_indent(ZigValue *val, int indent) {
9475 for (int i = 0; i < indent; i += 1) {9611 for (int i = 0; i < indent; i += 1) {
9476 fprintf(stderr, " ");9612 fprintf(stderr, " ");
...@@ -9548,15 +9684,20 @@ static void dump_value_indent(ZigValue *val, int indent) {...@@ -9548,15 +9684,20 @@ static void dump_value_indent(ZigValue *val, int indent) {
9548 return;9684 return;
95499685
9550 case ZigTypeIdOptional:9686 case ZigTypeIdOptional:
9551 fprintf(stderr, "<\n");9687 if (get_src_ptr_type(val->type) != nullptr) {
9552 dump_value_indent(val->data.x_optional, indent + 1);9688 return dump_value_indent_ptr(val, indent);
9689 } else if (val->type->data.maybe.child_type->id == ZigTypeIdErrorSet) {
9690 return dump_value_indent_error_set(val, indent);
9691 } else {
9692 fprintf(stderr, "<\n");
9693 dump_value_indent(val->data.x_optional, indent + 1);
95539694
9554 for (int i = 0; i < indent; i += 1) {9695 for (int i = 0; i < indent; i += 1) {
9555 fprintf(stderr, " ");9696 fprintf(stderr, " ");
9697 }
9698 fprintf(stderr, ">\n");
9699 return;
9556 }9700 }
9557 fprintf(stderr, ">\n");
9558 return;
9559
9560 case ZigTypeIdErrorUnion:9701 case ZigTypeIdErrorUnion:
9561 if (val->data.x_err_union.payload != nullptr) {9702 if (val->data.x_err_union.payload != nullptr) {
9562 fprintf(stderr, "<\n");9703 fprintf(stderr, "<\n");
...@@ -9572,52 +9713,14 @@ static void dump_value_indent(ZigValue *val, int indent) {...@@ -9572,52 +9713,14 @@ static void dump_value_indent(ZigValue *val, int indent) {
9572 return;9713 return;
95739714
9574 case ZigTypeIdPointer:9715 case ZigTypeIdPointer:
9575 switch (val->data.x_ptr.special) {9716 return dump_value_indent_ptr(val, indent);
9576 case ConstPtrSpecialInvalid:9717
9577 fprintf(stderr, "<!invalid ptr!>\n");9718 case ZigTypeIdErrorSet:
9578 return;9719 return dump_value_indent_error_set(val, indent);
9579 case ConstPtrSpecialRef:
9580 fprintf(stderr, "<ref\n");
9581 dump_value_indent(val->data.x_ptr.data.ref.pointee, indent + 1);
9582 break;
9583 case ConstPtrSpecialBaseStruct: {
9584 ZigValue *struct_val = val->data.x_ptr.data.base_struct.struct_val;
9585 size_t field_index = val->data.x_ptr.data.base_struct.field_index;
9586 fprintf(stderr, "<struct %p field %zu\n", struct_val, field_index);
9587 if (struct_val != nullptr) {
9588 ZigValue *field_val = struct_val->data.x_struct.fields[field_index];
9589 if (field_val != nullptr) {
9590 dump_value_indent(field_val, indent + 1);
9591 } else {
9592 for (int i = 0; i < indent; i += 1) {
9593 fprintf(stderr, " ");
9594 }
9595 fprintf(stderr, "(invalid null field)\n");
9596 }
9597 }
9598 break;
9599 }
9600 case ConstPtrSpecialBaseOptionalPayload: {
9601 ZigValue *optional_val = val->data.x_ptr.data.base_optional_payload.optional_val;
9602 fprintf(stderr, "<optional %p payload\n", optional_val);
9603 if (optional_val != nullptr) {
9604 dump_value_indent(optional_val, indent + 1);
9605 }
9606 break;
9607 }
9608 default:
9609 fprintf(stderr, "TODO dump more pointer things\n");
9610 }
9611 for (int i = 0; i < indent; i += 1) {
9612 fprintf(stderr, " ");
9613 }
9614 fprintf(stderr, ">\n");
9615 return;
96169720
9617 case ZigTypeIdVector:9721 case ZigTypeIdVector:
9618 case ZigTypeIdArray:9722 case ZigTypeIdArray:
9619 case ZigTypeIdNull:9723 case ZigTypeIdNull:
9620 case ZigTypeIdErrorSet:
9621 case ZigTypeIdEnum:9724 case ZigTypeIdEnum:
9622 case ZigTypeIdUnion:9725 case ZigTypeIdUnion:
9623 case ZigTypeIdFn:9726 case ZigTypeIdFn:
src/analyze.hpp+12-6
...@@ -44,14 +44,20 @@ ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry);...@@ -44,14 +44,20 @@ ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry);
44ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *full_name, Buf *bare_name);44ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *full_name, Buf *bare_name);
45ZigType *get_test_fn_type(CodeGen *g);45ZigType *get_test_fn_type(CodeGen *g);
46ZigType *get_any_frame_type(CodeGen *g, ZigType *result_type);46ZigType *get_any_frame_type(CodeGen *g, ZigType *result_type);
47bool handle_is_ptr(ZigType *type_entry);47bool handle_is_ptr(CodeGen *g, ZigType *type_entry);
4848
49bool type_has_bits(ZigType *type_entry);49bool type_has_bits(CodeGen *g, ZigType *type_entry);
50Error type_has_bits2(CodeGen *g, ZigType *type_entry, bool *result);50Error type_has_bits2(CodeGen *g, ZigType *type_entry, bool *result);
5151
52Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result);52Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result);
53bool ptr_allows_addr_zero(ZigType *ptr_type);53bool ptr_allows_addr_zero(ZigType *ptr_type);
54bool type_is_nonnull_ptr(ZigType *type);54
55// Deprecated, use `type_is_nonnull_ptr2`
56bool type_is_nonnull_ptr(CodeGen *g, ZigType *type);
57Error type_is_nonnull_ptr2(CodeGen *g, ZigType *type, bool *result);
58
59ZigType *get_codegen_ptr_type_bail(CodeGen *g, ZigType *type);
60Error get_codegen_ptr_type(CodeGen *g, ZigType *type, ZigType **result);
5561
56enum SourceKind {62enum SourceKind {
57 SourceKindRoot,63 SourceKindRoot,
...@@ -68,7 +74,6 @@ Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name);...@@ -68,7 +74,6 @@ Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name);
68void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node, bool allow_lazy);74void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node, bool allow_lazy);
6975
70ZigType *get_src_ptr_type(ZigType *type);76ZigType *get_src_ptr_type(ZigType *type);
71ZigType *get_codegen_ptr_type(ZigType *type);
72uint32_t get_ptr_align(CodeGen *g, ZigType *type);77uint32_t get_ptr_align(CodeGen *g, ZigType *type);
73bool get_ptr_const(ZigType *type);78bool get_ptr_const(ZigType *type);
74ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry);79ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry);
...@@ -87,7 +92,7 @@ TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag);...@@ -87,7 +92,7 @@ TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag);
87bool is_ref(ZigType *type_entry);92bool is_ref(ZigType *type_entry);
88bool is_array_ref(ZigType *type_entry);93bool is_array_ref(ZigType *type_entry);
89bool is_container_ref(ZigType *type_entry);94bool is_container_ref(ZigType *type_entry);
90bool is_valid_vector_elem_type(ZigType *elem_type);95Error is_valid_vector_elem_type(CodeGen *g, ZigType *elem_type, bool *result);
91void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node);96void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node);
92ZigFn *scope_fn_entry(Scope *scope);97ZigFn *scope_fn_entry(Scope *scope);
93ZigPackage *scope_package(Scope *scope);98ZigPackage *scope_package(Scope *scope);
...@@ -223,7 +228,8 @@ Error ATTRIBUTE_MUST_USE file_fetch(CodeGen *g, Buf *resolved_path, Buf *content...@@ -223,7 +228,8 @@ Error ATTRIBUTE_MUST_USE file_fetch(CodeGen *g, Buf *resolved_path, Buf *content
223228
224void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk);229void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk);
225X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty);230X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty);
226bool type_is_c_abi_int(CodeGen *g, ZigType *ty);231bool type_is_c_abi_int_bail(CodeGen *g, ZigType *ty);
232Error type_is_c_abi_int(CodeGen *g, ZigType *ty, bool *result);
227bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id);233bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id);
228const char *container_string(ContainerKind kind);234const char *container_string(ContainerKind kind);
229235
src/codegen.cpp+98-98
...@@ -313,7 +313,7 @@ struct CalcLLVMFieldIndex {...@@ -313,7 +313,7 @@ struct CalcLLVMFieldIndex {
313};313};
314314
315static void calc_llvm_field_index_add(CodeGen *g, CalcLLVMFieldIndex *calc, ZigType *ty) {315static void calc_llvm_field_index_add(CodeGen *g, CalcLLVMFieldIndex *calc, ZigType *ty) {
316 if (!type_has_bits(ty)) return;316 if (!type_has_bits(g, ty)) return;
317 uint32_t ty_align = get_abi_alignment(g, ty);317 uint32_t ty_align = get_abi_alignment(g, ty);
318 if (calc->offset % ty_align != 0) {318 if (calc->offset % ty_align != 0) {
319 uint32_t llvm_align = LLVMABIAlignmentOfType(g->target_data_ref, get_llvm_type(g, ty));319 uint32_t llvm_align = LLVMABIAlignmentOfType(g->target_data_ref, get_llvm_type(g, ty));
...@@ -334,7 +334,7 @@ static void frame_index_trace_arg_calc(CodeGen *g, CalcLLVMFieldIndex *calc, Zig...@@ -334,7 +334,7 @@ static void frame_index_trace_arg_calc(CodeGen *g, CalcLLVMFieldIndex *calc, Zig
334 calc_llvm_field_index_add(g, calc, g->builtin_types.entry_usize); // resume index334 calc_llvm_field_index_add(g, calc, g->builtin_types.entry_usize); // resume index
335 calc_llvm_field_index_add(g, calc, g->builtin_types.entry_usize); // awaiter index335 calc_llvm_field_index_add(g, calc, g->builtin_types.entry_usize); // awaiter index
336336
337 if (type_has_bits(return_type)) {337 if (type_has_bits(g, return_type)) {
338 calc_llvm_field_index_add(g, calc, g->builtin_types.entry_usize); // *ReturnType (callee's)338 calc_llvm_field_index_add(g, calc, g->builtin_types.entry_usize); // *ReturnType (callee's)
339 calc_llvm_field_index_add(g, calc, g->builtin_types.entry_usize); // *ReturnType (awaiter's)339 calc_llvm_field_index_add(g, calc, g->builtin_types.entry_usize); // *ReturnType (awaiter's)
340 calc_llvm_field_index_add(g, calc, return_type); // ReturnType340 calc_llvm_field_index_add(g, calc, return_type); // ReturnType
...@@ -383,7 +383,7 @@ static uint32_t get_err_ret_trace_arg_index(CodeGen *g, ZigFn *fn_table_entry) {...@@ -383,7 +383,7 @@ static uint32_t get_err_ret_trace_arg_index(CodeGen *g, ZigFn *fn_table_entry) {
383 return UINT32_MAX;383 return UINT32_MAX;
384 }384 }
385 ZigType *return_type = fn_type->data.fn.fn_type_id.return_type;385 ZigType *return_type = fn_type->data.fn.fn_type_id.return_type;
386 bool first_arg_ret = type_has_bits(return_type) && handle_is_ptr(return_type);386 bool first_arg_ret = type_has_bits(g, return_type) && handle_is_ptr(g, return_type);
387 return first_arg_ret ? 1 : 0;387 return first_arg_ret ? 1 : 0;
388}388}
389389
...@@ -581,9 +581,9 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {...@@ -581,9 +581,9 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
581 addLLVMArgAttr(llvm_fn, 0, "nonnull");581 addLLVMArgAttr(llvm_fn, 0, "nonnull");
582 } else {582 } else {
583 unsigned init_gen_i = 0;583 unsigned init_gen_i = 0;
584 if (!type_has_bits(return_type)) {584 if (!type_has_bits(g, return_type)) {
585 // nothing to do585 // nothing to do
586 } else if (type_is_nonnull_ptr(return_type)) {586 } else if (type_is_nonnull_ptr(g, return_type)) {
587 addLLVMAttr(llvm_fn, 0, "nonnull");587 addLLVMAttr(llvm_fn, 0, "nonnull");
588 } else if (want_first_arg_sret(g, &fn_type->data.fn.fn_type_id)) {588 } else if (want_first_arg_sret(g, &fn_type->data.fn.fn_type_id)) {
589 // Sret pointers must not be address 0589 // Sret pointers must not be address 0
...@@ -859,8 +859,8 @@ static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, co...@@ -859,8 +859,8 @@ static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, co
859}859}
860860
861static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type, ZigType *ptr_type) {861static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type, ZigType *ptr_type) {
862 if (type_has_bits(type)) {862 if (type_has_bits(g, type)) {
863 if (handle_is_ptr(type)) {863 if (handle_is_ptr(g, type)) {
864 return ptr;864 return ptr;
865 } else {865 } else {
866 assert(ptr_type->id == ZigTypeIdPointer);866 assert(ptr_type->id == ZigTypeIdPointer);
...@@ -1671,10 +1671,10 @@ static void gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type,...@@ -1671,10 +1671,10 @@ static void gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type,
1671 assert(ptr_type->id == ZigTypeIdPointer);1671 assert(ptr_type->id == ZigTypeIdPointer);
1672 ZigType *child_type = ptr_type->data.pointer.child_type;1672 ZigType *child_type = ptr_type->data.pointer.child_type;
16731673
1674 if (!type_has_bits(child_type))1674 if (!type_has_bits(g, child_type))
1675 return;1675 return;
16761676
1677 if (handle_is_ptr(child_type)) {1677 if (handle_is_ptr(g, child_type)) {
1678 assert(LLVMGetTypeKind(LLVMTypeOf(value)) == LLVMPointerTypeKind);1678 assert(LLVMGetTypeKind(LLVMTypeOf(value)) == LLVMPointerTypeKind);
1679 assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);1679 assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
16801680
...@@ -1782,7 +1782,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstGen *instruction) {...@@ -1782,7 +1782,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstGen *instruction) {
1782 render_const_val(g, instruction->value, "");1782 render_const_val(g, instruction->value, "");
1783 // we might have to do some pointer casting here due to the way union1783 // we might have to do some pointer casting here due to the way union
1784 // values are rendered with a type other than the one we expect1784 // values are rendered with a type other than the one we expect
1785 if (handle_is_ptr(instruction->value->type)) {1785 if (handle_is_ptr(g, instruction->value->type)) {
1786 render_const_val_global(g, instruction->value, "");1786 render_const_val_global(g, instruction->value, "");
1787 ZigType *ptr_type = get_pointer_to_type(g, instruction->value->type, true);1787 ZigType *ptr_type = get_pointer_to_type(g, instruction->value->type, true);
1788 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->llvm_global, get_llvm_type(g, ptr_type), "");1788 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->llvm_global, get_llvm_type(g, ptr_type), "");
...@@ -1879,14 +1879,14 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_...@@ -1879,14 +1879,14 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
1879 break;1879 break;
1880 }1880 }
18811881
1882 if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat || ty->id == ZigTypeIdVector ||1882 if (type_is_c_abi_int_bail(g, ty) || ty->id == ZigTypeIdFloat || ty->id == ZigTypeIdVector ||
1883 ty->id == ZigTypeIdInt // TODO investigate if we need to change this1883 ty->id == ZigTypeIdInt // TODO investigate if we need to change this
1884 ) {1884 ) {
1885 switch (fn_walk->id) {1885 switch (fn_walk->id) {
1886 case FnWalkIdAttrs: {1886 case FnWalkIdAttrs: {
1887 ZigType *ptr_type = get_codegen_ptr_type(ty);1887 ZigType *ptr_type = get_codegen_ptr_type_bail(g, ty);
1888 if (ptr_type != nullptr) {1888 if (ptr_type != nullptr) {
1889 if (type_is_nonnull_ptr(ty)) {1889 if (type_is_nonnull_ptr(g, ty)) {
1890 addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull");1890 addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull");
1891 }1891 }
1892 if (ptr_type->data.pointer.is_const) {1892 if (ptr_type->data.pointer.is_const) {
...@@ -1928,7 +1928,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_...@@ -1928,7 +1928,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
1928 {1928 {
1929 // Arrays are just pointers1929 // Arrays are just pointers
1930 if (ty->id == ZigTypeIdArray) {1930 if (ty->id == ZigTypeIdArray) {
1931 assert(handle_is_ptr(ty));1931 assert(handle_is_ptr(g, ty));
1932 switch (fn_walk->id) {1932 switch (fn_walk->id) {
1933 case FnWalkIdAttrs:1933 case FnWalkIdAttrs:
1934 // arrays passed to C ABI functions may not be at address 01934 // arrays passed to C ABI functions may not be at address 0
...@@ -1965,7 +1965,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_...@@ -1965,7 +1965,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
1965 X64CABIClass abi_class = type_c_abi_x86_64_class(g, ty);1965 X64CABIClass abi_class = type_c_abi_x86_64_class(g, ty);
1966 size_t ty_size = type_size(g, ty);1966 size_t ty_size = type_size(g, ty);
1967 if (abi_class == X64CABIClass_MEMORY || abi_class == X64CABIClass_MEMORY_nobyval) {1967 if (abi_class == X64CABIClass_MEMORY || abi_class == X64CABIClass_MEMORY_nobyval) {
1968 assert(handle_is_ptr(ty));1968 assert(handle_is_ptr(g, ty));
1969 switch (fn_walk->id) {1969 switch (fn_walk->id) {
1970 case FnWalkIdAttrs:1970 case FnWalkIdAttrs:
1971 if (abi_class != X64CABIClass_MEMORY_nobyval) {1971 if (abi_class != X64CABIClass_MEMORY_nobyval) {
...@@ -2088,7 +2088,7 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {...@@ -2088,7 +2088,7 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
2088 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {2088 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {
2089 IrInstGen *param_instruction = instruction->args[call_i];2089 IrInstGen *param_instruction = instruction->args[call_i];
2090 ZigType *param_type = param_instruction->value->type;2090 ZigType *param_type = param_instruction->value->type;
2091 if (is_var_args || type_has_bits(param_type)) {2091 if (is_var_args || type_has_bits(g, param_type)) {
2092 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);2092 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);
2093 assert(param_value);2093 assert(param_value);
2094 fn_walk->data.call.gen_param_values->append(param_value);2094 fn_walk->data.call.gen_param_values->append(param_value);
...@@ -2119,10 +2119,10 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {...@@ -2119,10 +2119,10 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
2119 if ((param_type->id == ZigTypeIdPointer && param_type->data.pointer.is_const) || is_byval) {2119 if ((param_type->id == ZigTypeIdPointer && param_type->data.pointer.is_const) || is_byval) {
2120 addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "readonly");2120 addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "readonly");
2121 }2121 }
2122 if (get_codegen_ptr_type(param_type) != nullptr) {2122 if (get_codegen_ptr_type_bail(g, param_type) != nullptr) {
2123 addLLVMArgAttrInt(llvm_fn, (unsigned)gen_index, "align", get_ptr_align(g, param_type));2123 addLLVMArgAttrInt(llvm_fn, (unsigned)gen_index, "align", get_ptr_align(g, param_type));
2124 }2124 }
2125 if (type_is_nonnull_ptr(param_type)) {2125 if (type_is_nonnull_ptr(g, param_type)) {
2126 addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "nonnull");2126 addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "nonnull");
2127 }2127 }
2128 break;2128 break;
...@@ -2137,7 +2137,7 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {...@@ -2137,7 +2137,7 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
2137 assert(variable);2137 assert(variable);
2138 assert(variable->value_ref);2138 assert(variable->value_ref);
21392139
2140 if (!handle_is_ptr(variable->var_type) && !fn_is_async(fn_walk->data.inits.fn)) {2140 if (!handle_is_ptr(g, variable->var_type) && !fn_is_async(fn_walk->data.inits.fn)) {
2141 clear_debug_source_node(g);2141 clear_debug_source_node(g);
2142 ZigType *fn_type = fn_table_entry->type_entry;2142 ZigType *fn_type = fn_table_entry->type_entry;
2143 unsigned gen_arg_index = fn_type->data.fn.gen_param_info[variable->src_arg_index].gen_index;2143 unsigned gen_arg_index = fn_type->data.fn.gen_param_info[variable->src_arg_index].gen_index;
...@@ -2404,12 +2404,12 @@ static void gen_async_return(CodeGen *g, IrInstGenReturn *instruction) {...@@ -2404,12 +2404,12 @@ static void gen_async_return(CodeGen *g, IrInstGenReturn *instruction) {
2404 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;2404 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
24052405
2406 ZigType *operand_type = (instruction->operand != nullptr) ? instruction->operand->value->type : nullptr;2406 ZigType *operand_type = (instruction->operand != nullptr) ? instruction->operand->value->type : nullptr;
2407 bool operand_has_bits = (operand_type != nullptr) && type_has_bits(operand_type);2407 bool operand_has_bits = (operand_type != nullptr) && type_has_bits(g, operand_type);
2408 ZigType *ret_type = g->cur_fn->type_entry->data.fn.fn_type_id.return_type;2408 ZigType *ret_type = g->cur_fn->type_entry->data.fn.fn_type_id.return_type;
2409 bool ret_type_has_bits = type_has_bits(ret_type);2409 bool ret_type_has_bits = type_has_bits(g, ret_type);
24102410
2411 if (operand_has_bits && instruction->operand != nullptr) {2411 if (operand_has_bits && instruction->operand != nullptr) {
2412 bool need_store = instruction->operand->value->special != ConstValSpecialRuntime || !handle_is_ptr(ret_type);2412 bool need_store = instruction->operand->value->special != ConstValSpecialRuntime || !handle_is_ptr(g, ret_type);
2413 if (need_store) {2413 if (need_store) {
2414 // It didn't get written to the result ptr. We do that now.2414 // It didn't get written to the result ptr. We do that now.
2415 ZigType *ret_ptr_type = get_pointer_to_type(g, ret_type, true);2415 ZigType *ret_ptr_type = get_pointer_to_type(g, ret_type, true);
...@@ -2512,7 +2512,7 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutableGen *executable, Ir...@@ -2512,7 +2512,7 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutableGen *executable, Ir
2512 gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);2512 gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);
2513 LLVMBuildRetVoid(g->builder);2513 LLVMBuildRetVoid(g->builder);
2514 } else if (g->cur_fn->type_entry->data.fn.fn_type_id.cc != CallingConventionAsync &&2514 } else if (g->cur_fn->type_entry->data.fn.fn_type_id.cc != CallingConventionAsync &&
2515 handle_is_ptr(g->cur_fn->type_entry->data.fn.fn_type_id.return_type))2515 handle_is_ptr(g, g->cur_fn->type_entry->data.fn.fn_type_id.return_type))
2516 {2516 {
2517 if (instruction->operand == nullptr) {2517 if (instruction->operand == nullptr) {
2518 LLVMValueRef by_val_value = gen_load_untyped(g, g->cur_ret_ptr, 0, false, "");2518 LLVMValueRef by_val_value = gen_load_untyped(g, g->cur_ret_ptr, 0, false, "");
...@@ -2883,7 +2883,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutableGen *executable,...@@ -2883,7 +2883,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutableGen *executable,
2883 } else if (scalar_type->id == ZigTypeIdEnum ||2883 } else if (scalar_type->id == ZigTypeIdEnum ||
2884 scalar_type->id == ZigTypeIdErrorSet ||2884 scalar_type->id == ZigTypeIdErrorSet ||
2885 scalar_type->id == ZigTypeIdBool ||2885 scalar_type->id == ZigTypeIdBool ||
2886 get_codegen_ptr_type(scalar_type) != nullptr)2886 get_codegen_ptr_type_bail(g, scalar_type) != nullptr)
2887 {2887 {
2888 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);2888 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);
2889 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");2889 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");
...@@ -3149,7 +3149,7 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutableGen...@@ -3149,7 +3149,7 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutableGen
3149 ZigType *array_type = actual_type->data.pointer.child_type;3149 ZigType *array_type = actual_type->data.pointer.child_type;
3150 assert(array_type->id == ZigTypeIdArray);3150 assert(array_type->id == ZigTypeIdArray);
31513151
3152 if (type_has_bits(actual_type)) {3152 if (type_has_bits(g, actual_type)) {
3153 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, result_loc, ptr_index, "");3153 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, result_loc, ptr_index, "");
3154 LLVMValueRef indices[] = {3154 LLVMValueRef indices[] = {
3155 LLVMConstNull(g->builtin_types.entry_usize->llvm_type),3155 LLVMConstNull(g->builtin_types.entry_usize->llvm_type),
...@@ -3175,7 +3175,7 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutableGen *executable,...@@ -3175,7 +3175,7 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutableGen *executable,
3175 IrInstGenPtrCast *instruction)3175 IrInstGenPtrCast *instruction)
3176{3176{
3177 ZigType *wanted_type = instruction->base.value->type;3177 ZigType *wanted_type = instruction->base.value->type;
3178 if (!type_has_bits(wanted_type)) {3178 if (!type_has_bits(g, wanted_type)) {
3179 return nullptr;3179 return nullptr;
3180 }3180 }
3181 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);3181 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
...@@ -3204,8 +3204,8 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutableGen *executable,...@@ -3204,8 +3204,8 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutableGen *executable,
3204 ZigType *actual_type = instruction->operand->value->type;3204 ZigType *actual_type = instruction->operand->value->type;
3205 LLVMValueRef value = ir_llvm_value(g, instruction->operand);3205 LLVMValueRef value = ir_llvm_value(g, instruction->operand);
32063206
3207 bool wanted_is_ptr = handle_is_ptr(wanted_type);3207 bool wanted_is_ptr = handle_is_ptr(g, wanted_type);
3208 bool actual_is_ptr = handle_is_ptr(actual_type);3208 bool actual_is_ptr = handle_is_ptr(g, actual_type);
3209 if (wanted_is_ptr == actual_is_ptr) {3209 if (wanted_is_ptr == actual_is_ptr) {
3210 // We either bitcast the value directly or bitcast the pointer which does a pointer cast3210 // We either bitcast the value directly or bitcast the pointer which does a pointer cast
3211 LLVMTypeRef wanted_type_ref = wanted_is_ptr ?3211 LLVMTypeRef wanted_type_ref = wanted_is_ptr ?
...@@ -3352,9 +3352,9 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutableGen *executable...@@ -3352,9 +3352,9 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutableGen *executable
3352 g->err_tag_type, wanted_type, target_val);3352 g->err_tag_type, wanted_type, target_val);
3353 } else if (actual_type->id == ZigTypeIdErrorUnion) {3353 } else if (actual_type->id == ZigTypeIdErrorUnion) {
3354 // this should have been a compile time constant3354 // this should have been a compile time constant
3355 assert(type_has_bits(actual_type->data.error_union.err_set_type));3355 assert(type_has_bits(g, actual_type->data.error_union.err_set_type));
33563356
3357 if (!type_has_bits(actual_type->data.error_union.payload_type)) {3357 if (!type_has_bits(g, actual_type->data.error_union.payload_type)) {
3358 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),3358 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
3359 g->err_tag_type, wanted_type, target_val);3359 g->err_tag_type, wanted_type, target_val);
3360 } else {3360 } else {
...@@ -3442,7 +3442,7 @@ static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutableGen *executable,...@@ -3442,7 +3442,7 @@ static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutableGen *executable,
3442}3442}
34433443
3444static void render_decl_var(CodeGen *g, ZigVar *var) {3444static void render_decl_var(CodeGen *g, ZigVar *var) {
3445 if (!type_has_bits(var->var_type))3445 if (!type_has_bits(g, var->var_type))
3446 return;3446 return;
34473447
3448 var->value_ref = ir_llvm_value(g, var->ptr_instruction);3448 var->value_ref = ir_llvm_value(g, var->ptr_instruction);
...@@ -3460,7 +3460,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutableGen *executable,...@@ -3460,7 +3460,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutableGen *executable,
3460 IrInstGenLoadPtr *instruction)3460 IrInstGenLoadPtr *instruction)
3461{3461{
3462 ZigType *child_type = instruction->base.value->type;3462 ZigType *child_type = instruction->base.value->type;
3463 if (!type_has_bits(child_type))3463 if (!type_has_bits(g, child_type))
3464 return nullptr;3464 return nullptr;
34653465
3466 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);3466 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
...@@ -3495,7 +3495,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutableGen *executable,...@@ -3495,7 +3495,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutableGen *executable,
3495 LLVMValueRef shift_amt_val = LLVMConstInt(LLVMTypeOf(containing_int), shift_amt, false);3495 LLVMValueRef shift_amt_val = LLVMConstInt(LLVMTypeOf(containing_int), shift_amt, false);
3496 LLVMValueRef shifted_value = LLVMBuildLShr(g->builder, containing_int, shift_amt_val, "");3496 LLVMValueRef shifted_value = LLVMBuildLShr(g->builder, containing_int, shift_amt_val, "");
34973497
3498 if (handle_is_ptr(child_type)) {3498 if (handle_is_ptr(g, child_type)) {
3499 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);3499 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
3500 LLVMTypeRef same_size_int = LLVMIntType(size_in_bits);3500 LLVMTypeRef same_size_int = LLVMIntType(size_in_bits);
3501 LLVMValueRef truncated_int = LLVMBuildTrunc(g->builder, shifted_value, same_size_int, "");3501 LLVMValueRef truncated_int = LLVMBuildTrunc(g->builder, shifted_value, same_size_int, "");
...@@ -3642,7 +3642,7 @@ static void gen_valgrind_undef(CodeGen *g, LLVMValueRef dest_ptr, LLVMValueRef b...@@ -3642,7 +3642,7 @@ static void gen_valgrind_undef(CodeGen *g, LLVMValueRef dest_ptr, LLVMValueRef b
3642}3642}
36433643
3644static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr) {3644static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr) {
3645 assert(type_has_bits(value_type));3645 assert(type_has_bits(g, value_type));
3646 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, get_llvm_type(g, value_type));3646 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, get_llvm_type(g, value_type));
3647 assert(size_bytes > 0);3647 assert(size_bytes > 0);
3648 assert(ptr_align_bytes > 0);3648 assert(ptr_align_bytes > 0);
...@@ -3708,7 +3708,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutableGen *executable, I...@@ -3708,7 +3708,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutableGen *executable, I
3708 if (instruction->base.value->special != ConstValSpecialRuntime)3708 if (instruction->base.value->special != ConstValSpecialRuntime)
3709 return ir_llvm_value(g, &instruction->base);3709 return ir_llvm_value(g, &instruction->base);
3710 ZigVar *var = instruction->var;3710 ZigVar *var = instruction->var;
3711 if (type_has_bits(var->var_type)) {3711 if (type_has_bits(g, var->var_type)) {
3712 assert(var->value_ref);3712 assert(var->value_ref);
3713 return var->value_ref;3713 return var->value_ref;
3714 } else {3714 } else {
...@@ -3719,7 +3719,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutableGen *executable, I...@@ -3719,7 +3719,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutableGen *executable, I
3719static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutableGen *executable,3719static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutableGen *executable,
3720 IrInstGenReturnPtr *instruction)3720 IrInstGenReturnPtr *instruction)
3721{3721{
3722 if (!type_has_bits(instruction->base.value->type))3722 if (!type_has_bits(g, instruction->base.value->type))
3723 return nullptr;3723 return nullptr;
3724 ir_assert(g->cur_ret_ptr != nullptr, &instruction->base);3724 ir_assert(g->cur_ret_ptr != nullptr, &instruction->base);
3725 return g->cur_ret_ptr;3725 return g->cur_ret_ptr;
...@@ -3733,7 +3733,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutableGen *executable,...@@ -3733,7 +3733,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutableGen *executable,
3733 LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index);3733 LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index);
3734 assert(subscript_value);3734 assert(subscript_value);
37353735
3736 if (!type_has_bits(array_type))3736 if (!type_has_bits(g, array_type))
3737 return nullptr;3737 return nullptr;
37383738
3739 bool safety_check_on = ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on;3739 bool safety_check_on = ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on;
...@@ -3793,7 +3793,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutableGen *executable,...@@ -3793,7 +3793,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutableGen *executable,
3793 assert(array_type->data.structure.special == StructSpecialSlice);3793 assert(array_type->data.structure.special == StructSpecialSlice);
37943794
3795 ZigType *ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;3795 ZigType *ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;
3796 if (!type_has_bits(ptr_type)) {3796 if (!type_has_bits(g, ptr_type)) {
3797 if (safety_check_on) {3797 if (safety_check_on) {
3798 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMIntegerTypeKind);3798 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMIntegerTypeKind);
3799 add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, array_ptr);3799 add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, array_ptr);
...@@ -3872,7 +3872,7 @@ static void render_async_spills(CodeGen *g) {...@@ -3872,7 +3872,7 @@ static void render_async_spills(CodeGen *g) {
3872 for (size_t var_i = 0; var_i < g->cur_fn->variable_list.length; var_i += 1) {3872 for (size_t var_i = 0; var_i < g->cur_fn->variable_list.length; var_i += 1) {
3873 ZigVar *var = g->cur_fn->variable_list.at(var_i);3873 ZigVar *var = g->cur_fn->variable_list.at(var_i);
38743874
3875 if (!type_has_bits(var->var_type)) {3875 if (!type_has_bits(g, var->var_type)) {
3876 continue;3876 continue;
3877 }3877 }
3878 if (ir_get_var_is_comptime(var))3878 if (ir_get_var_is_comptime(var))
...@@ -3992,7 +3992,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn...@@ -3992,7 +3992,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
3992 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;3992 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
39933993
3994 ZigType *src_return_type = fn_type_id->return_type;3994 ZigType *src_return_type = fn_type_id->return_type;
3995 bool ret_has_bits = type_has_bits(src_return_type);3995 bool ret_has_bits = type_has_bits(g, src_return_type);
39963996
3997 CallingConvention cc = fn_type->data.fn.fn_type_id.cc;3997 CallingConvention cc = fn_type->data.fn.fn_type_id.cc;
39983998
...@@ -4312,7 +4312,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn...@@ -4312,7 +4312,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
4312 gen_assert_resume_id(g, &instruction->base, ResumeIdReturn, PanicMsgIdResumedAnAwaitingFn, nullptr);4312 gen_assert_resume_id(g, &instruction->base, ResumeIdReturn, PanicMsgIdResumedAnAwaitingFn, nullptr);
4313 render_async_var_decls(g, instruction->base.base.scope);4313 render_async_var_decls(g, instruction->base.base.scope);
43144314
4315 if (!type_has_bits(src_return_type))4315 if (!type_has_bits(g, src_return_type))
4316 return nullptr;4316 return nullptr;
43174317
4318 if (result_loc != nullptr) {4318 if (result_loc != nullptr) {
...@@ -4372,7 +4372,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn...@@ -4372,7 +4372,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
4372 } else if (first_arg_ret) {4372 } else if (first_arg_ret) {
4373 set_call_instr_sret(g, result);4373 set_call_instr_sret(g, result);
4374 return result_loc;4374 return result_loc;
4375 } else if (handle_is_ptr(src_return_type)) {4375 } else if (handle_is_ptr(g, src_return_type)) {
4376 LLVMValueRef store_instr = LLVMBuildStore(g->builder, result, result_loc);4376 LLVMValueRef store_instr = LLVMBuildStore(g->builder, result, result_loc);
4377 LLVMSetAlignment(store_instr, get_ptr_align(g, instruction->result_loc->value->type));4377 LLVMSetAlignment(store_instr, get_ptr_align(g, instruction->result_loc->value->type));
4378 return result_loc;4378 return result_loc;
...@@ -4397,7 +4397,7 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutableGen *exec...@@ -4397,7 +4397,7 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutableGen *exec
4397 ZigType *struct_ptr_type = instruction->struct_ptr->value->type;4397 ZigType *struct_ptr_type = instruction->struct_ptr->value->type;
4398 TypeStructField *field = instruction->field;4398 TypeStructField *field = instruction->field;
43994399
4400 if (!type_has_bits(field->type_entry))4400 if (!type_has_bits(g, field->type_entry))
4401 return nullptr;4401 return nullptr;
44024402
4403 if (struct_ptr_type->id == ZigTypeIdPointer &&4403 if (struct_ptr_type->id == ZigTypeIdPointer &&
...@@ -4448,9 +4448,9 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutableGen *execu...@@ -4448,9 +4448,9 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutableGen *execu
44484448
4449 TypeUnionField *field = instruction->field;4449 TypeUnionField *field = instruction->field;
44504450
4451 if (!type_has_bits(field->type_entry)) {4451 if (!type_has_bits(g, field->type_entry)) {
4452 ZigType *tag_type = union_type->data.unionation.tag_type;4452 ZigType *tag_type = union_type->data.unionation.tag_type;
4453 if (!instruction->initializing || tag_type == nullptr || !type_has_bits(tag_type))4453 if (!instruction->initializing || tag_type == nullptr || !type_has_bits(g, tag_type))
4454 return nullptr;4454 return nullptr;
44554455
4456 // The field has no bits but we still have to change the discriminant4456 // The field has no bits but we still have to change the discriminant
...@@ -4672,10 +4672,10 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR...@@ -4672,10 +4672,10 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR
4672 (maybe_type->id == ZigTypeIdPointer && maybe_type->data.pointer.allow_zero));4672 (maybe_type->id == ZigTypeIdPointer && maybe_type->data.pointer.allow_zero));
46734673
4674 ZigType *child_type = maybe_type->data.maybe.child_type;4674 ZigType *child_type = maybe_type->data.maybe.child_type;
4675 if (!type_has_bits(child_type))4675 if (!type_has_bits(g, child_type))
4676 return maybe_handle;4676 return maybe_handle;
46774677
4678 bool is_scalar = !handle_is_ptr(maybe_type);4678 bool is_scalar = !handle_is_ptr(g, maybe_type);
4679 if (is_scalar)4679 if (is_scalar)
4680 return LLVMBuildICmp(g->builder, LLVMIntNE, maybe_handle, LLVMConstNull(get_llvm_type(g, maybe_type)), "");4680 return LLVMBuildICmp(g->builder, LLVMIntNE, maybe_handle, LLVMConstNull(get_llvm_type(g, maybe_type)), "");
46814681
...@@ -4713,14 +4713,14 @@ static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutableGen *e...@@ -4713,14 +4713,14 @@ static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutableGen *e
47134713
4714 LLVMPositionBuilderAtEnd(g->builder, ok_block);4714 LLVMPositionBuilderAtEnd(g->builder, ok_block);
4715 }4715 }
4716 if (!type_has_bits(child_type)) {4716 if (!type_has_bits(g, child_type)) {
4717 if (instruction->initializing) {4717 if (instruction->initializing) {
4718 LLVMValueRef non_null_bit = LLVMConstInt(LLVMInt1Type(), 1, false);4718 LLVMValueRef non_null_bit = LLVMConstInt(LLVMInt1Type(), 1, false);
4719 gen_store_untyped(g, non_null_bit, base_ptr, 0, false);4719 gen_store_untyped(g, non_null_bit, base_ptr, 0, false);
4720 }4720 }
4721 return nullptr;4721 return nullptr;
4722 } else {4722 } else {
4723 bool is_scalar = !handle_is_ptr(maybe_type);4723 bool is_scalar = !handle_is_ptr(g, maybe_type);
4724 if (is_scalar) {4724 if (is_scalar) {
4725 return base_ptr;4725 return base_ptr;
4726 } else {4726 } else {
...@@ -4899,11 +4899,11 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutableGen *executable,...@@ -4899,11 +4899,11 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutableGen *executable,
4899}4899}
49004900
4901static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrInstGenPhi *instruction) {4901static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrInstGenPhi *instruction) {
4902 if (!type_has_bits(instruction->base.value->type))4902 if (!type_has_bits(g, instruction->base.value->type))
4903 return nullptr;4903 return nullptr;
49044904
4905 LLVMTypeRef phi_type;4905 LLVMTypeRef phi_type;
4906 if (handle_is_ptr(instruction->base.value->type)) {4906 if (handle_is_ptr(g, instruction->base.value->type)) {
4907 phi_type = LLVMPointerType(get_llvm_type(g,instruction->base.value->type), 0);4907 phi_type = LLVMPointerType(get_llvm_type(g,instruction->base.value->type), 0);
4908 } else {4908 } else {
4909 phi_type = get_llvm_type(g, instruction->base.value->type);4909 phi_type = get_llvm_type(g, instruction->base.value->type);
...@@ -4921,7 +4921,7 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrIns...@@ -4921,7 +4921,7 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrIns
4921}4921}
49224922
4923static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutableGen *executable, IrInstGenRef *instruction) {4923static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutableGen *executable, IrInstGenRef *instruction) {
4924 if (!type_has_bits(instruction->base.value->type)) {4924 if (!type_has_bits(g, instruction->base.value->type)) {
4925 return nullptr;4925 return nullptr;
4926 }4926 }
4927 if (instruction->operand->id == IrInstGenIdCall) {4927 if (instruction->operand->id == IrInstGenIdCall) {
...@@ -4931,7 +4931,7 @@ static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutableGen *executable, IrIns...@@ -4931,7 +4931,7 @@ static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutableGen *executable, IrIns
4931 }4931 }
4932 }4932 }
4933 LLVMValueRef value = ir_llvm_value(g, instruction->operand);4933 LLVMValueRef value = ir_llvm_value(g, instruction->operand);
4934 if (handle_is_ptr(instruction->operand->value->type)) {4934 if (handle_is_ptr(g, instruction->operand->value->type)) {
4935 return value;4935 return value;
4936 } else {4936 } else {
4937 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);4937 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
...@@ -5232,20 +5232,20 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutableGen *executable, I...@@ -5232,20 +5232,20 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutableGen *executable, I
5232 assert(optional_type->id == ZigTypeIdOptional);5232 assert(optional_type->id == ZigTypeIdOptional);
5233 ZigType *child_type = optional_type->data.maybe.child_type;5233 ZigType *child_type = optional_type->data.maybe.child_type;
52345234
5235 if (!handle_is_ptr(optional_type)) {5235 if (!handle_is_ptr(g, optional_type)) {
5236 LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, "");5236 LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, "");
5237 LLVMValueRef success_bit = LLVMBuildExtractValue(g->builder, result_val, 1, "");5237 LLVMValueRef success_bit = LLVMBuildExtractValue(g->builder, result_val, 1, "");
5238 return LLVMBuildSelect(g->builder, success_bit, LLVMConstNull(get_llvm_type(g, child_type)), payload_val, "");5238 return LLVMBuildSelect(g->builder, success_bit, LLVMConstNull(get_llvm_type(g, child_type)), payload_val, "");
5239 }5239 }
52405240
5241 // When the cmpxchg is discarded, the result location will have no bits.5241 // When the cmpxchg is discarded, the result location will have no bits.
5242 if (!type_has_bits(instruction->result_loc->value->type)) {5242 if (!type_has_bits(g, instruction->result_loc->value->type)) {
5243 return nullptr;5243 return nullptr;
5244 }5244 }
52455245
5246 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);5246 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
5247 ir_assert(result_loc != nullptr, &instruction->base);5247 ir_assert(result_loc != nullptr, &instruction->base);
5248 ir_assert(type_has_bits(child_type), &instruction->base);5248 ir_assert(type_has_bits(g, child_type), &instruction->base);
52495249
5250 LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, "");5250 LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, "");
5251 LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, result_loc, maybe_child_index, "");5251 LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, result_loc, maybe_child_index, "");
...@@ -5373,7 +5373,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrI...@@ -5373,7 +5373,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrI
5373 }5373 }
5374 }5374 }
5375 }5375 }
5376 if (!type_has_bits(array_type)) {5376 if (!type_has_bits(g, array_type)) {
5377 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, slice_len_index, "");5377 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, slice_len_index, "");
53785378
5379 // TODO if runtime safety is on, store 0xaaaaaaa in ptr field5379 // TODO if runtime safety is on, store 0xaaaaaaa in ptr field
...@@ -5409,7 +5409,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrI...@@ -5409,7 +5409,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrI
5409 }5409 }
5410 }5410 }
54115411
5412 if (type_has_bits(array_type)) {5412 if (type_has_bits(g, array_type)) {
5413 size_t gen_ptr_index = instruction->base.value->type->data.structure.fields[slice_ptr_index]->gen_index;5413 size_t gen_ptr_index = instruction->base.value->type->data.structure.fields[slice_ptr_index]->gen_index;
5414 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, "");5414 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, "");
5415 LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, "");5415 LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, "");
...@@ -5597,7 +5597,7 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutableGen *executable,...@@ -5597,7 +5597,7 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutableGen *executable,
5597 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union);5597 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union);
55985598
5599 LLVMValueRef err_val;5599 LLVMValueRef err_val;
5600 if (type_has_bits(payload_type)) {5600 if (type_has_bits(g, payload_type)) {
5601 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, err_union_handle, err_union_err_index, "");5601 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, err_union_handle, err_union_err_index, "");
5602 err_val = gen_load_untyped(g, err_val_ptr, 0, false, "");5602 err_val = gen_load_untyped(g, err_val_ptr, 0, false, "");
5603 } else {5603 } else {
...@@ -5619,7 +5619,7 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutableGen *execu...@@ -5619,7 +5619,7 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutableGen *execu
5619 ZigType *err_union_type = ptr_type->data.pointer.child_type;5619 ZigType *err_union_type = ptr_type->data.pointer.child_type;
5620 ZigType *payload_type = err_union_type->data.error_union.payload_type;5620 ZigType *payload_type = err_union_type->data.error_union.payload_type;
5621 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->err_union_ptr);5621 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->err_union_ptr);
5622 if (!type_has_bits(payload_type)) {5622 if (!type_has_bits(g, payload_type)) {
5623 return err_union_ptr;5623 return err_union_ptr;
5624 } else {5624 } else {
5625 // TODO assign undef to the payload5625 // TODO assign undef to the payload
...@@ -5659,13 +5659,13 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutableGen *ex...@@ -5659,13 +5659,13 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutableGen *ex
56595659
5660 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, ptr_type);5660 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, ptr_type);
56615661
5662 if (!type_has_bits(err_union_type->data.error_union.err_set_type)) {5662 if (!type_has_bits(g, err_union_type->data.error_union.err_set_type)) {
5663 return err_union_handle;5663 return err_union_handle;
5664 }5664 }
56655665
5666 if (want_safety) {5666 if (want_safety) {
5667 LLVMValueRef err_val;5667 LLVMValueRef err_val;
5668 if (type_has_bits(payload_type)) {5668 if (type_has_bits(g, payload_type)) {
5669 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, err_union_handle, err_union_err_index, "");5669 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, err_union_handle, err_union_err_index, "");
5670 err_val = gen_load_untyped(g, err_val_ptr, 0, false, "");5670 err_val = gen_load_untyped(g, err_val_ptr, 0, false, "");
5671 } else {5671 } else {
...@@ -5682,7 +5682,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutableGen *ex...@@ -5682,7 +5682,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutableGen *ex
5682 LLVMPositionBuilderAtEnd(g->builder, ok_block);5682 LLVMPositionBuilderAtEnd(g->builder, ok_block);
5683 }5683 }
56845684
5685 if (type_has_bits(payload_type)) {5685 if (type_has_bits(g, payload_type)) {
5686 if (instruction->initializing) {5686 if (instruction->initializing) {
5687 LLVMValueRef err_tag_ptr = LLVMBuildStructGEP(g->builder, err_union_handle, err_union_err_index, "");5687 LLVMValueRef err_tag_ptr = LLVMBuildStructGEP(g->builder, err_union_handle, err_union_err_index, "");
5688 LLVMValueRef ok_err_val = LLVMConstNull(get_llvm_type(g, g->err_tag_type));5688 LLVMValueRef ok_err_val = LLVMConstNull(get_llvm_type(g, g->err_tag_type));
...@@ -5704,7 +5704,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutableGen *executa...@@ -5704,7 +5704,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutableGen *executa
57045704
5705 ZigType *child_type = wanted_type->data.maybe.child_type;5705 ZigType *child_type = wanted_type->data.maybe.child_type;
57065706
5707 if (!type_has_bits(child_type)) {5707 if (!type_has_bits(g, child_type)) {
5708 LLVMValueRef result = LLVMConstAllOnes(LLVMInt1Type());5708 LLVMValueRef result = LLVMConstAllOnes(LLVMInt1Type());
5709 if (instruction->result_loc != nullptr) {5709 if (instruction->result_loc != nullptr) {
5710 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);5710 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
...@@ -5714,7 +5714,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutableGen *executa...@@ -5714,7 +5714,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutableGen *executa
5714 }5714 }
57155715
5716 LLVMValueRef payload_val = ir_llvm_value(g, instruction->operand);5716 LLVMValueRef payload_val = ir_llvm_value(g, instruction->operand);
5717 if (!handle_is_ptr(wanted_type)) {5717 if (!handle_is_ptr(g, wanted_type)) {
5718 if (instruction->result_loc != nullptr) {5718 if (instruction->result_loc != nullptr) {
5719 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);5719 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
5720 gen_store_untyped(g, payload_val, result_loc, 0, false);5720 gen_store_untyped(g, payload_val, result_loc, 0, false);
...@@ -5740,7 +5740,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutableGen *executa...@@ -5740,7 +5740,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutableGen *executa
57405740
5741 LLVMValueRef err_val = ir_llvm_value(g, instruction->operand);5741 LLVMValueRef err_val = ir_llvm_value(g, instruction->operand);
57425742
5743 if (!handle_is_ptr(wanted_type))5743 if (!handle_is_ptr(g, wanted_type))
5744 return err_val;5744 return err_val;
57455745
5746 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);5746 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
...@@ -5761,13 +5761,13 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutableGen *exec...@@ -5761,13 +5761,13 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutableGen *exec
5761 ZigType *payload_type = wanted_type->data.error_union.payload_type;5761 ZigType *payload_type = wanted_type->data.error_union.payload_type;
5762 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;5762 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
57635763
5764 if (!type_has_bits(err_set_type)) {5764 if (!type_has_bits(g, err_set_type)) {
5765 return ir_llvm_value(g, instruction->operand);5765 return ir_llvm_value(g, instruction->operand);
5766 }5766 }
57675767
5768 LLVMValueRef ok_err_val = LLVMConstNull(get_llvm_type(g, g->err_tag_type));5768 LLVMValueRef ok_err_val = LLVMConstNull(get_llvm_type(g, g->err_tag_type));
57695769
5770 if (!type_has_bits(payload_type))5770 if (!type_has_bits(g, payload_type))
5771 return ok_err_val;5771 return ok_err_val;
57725772
57735773
...@@ -5788,7 +5788,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutableGen *executable,...@@ -5788,7 +5788,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutableGen *executable,
5788 ZigType *union_type = instruction->value->value->type;5788 ZigType *union_type = instruction->value->value->type;
57895789
5790 ZigType *tag_type = union_type->data.unionation.tag_type;5790 ZigType *tag_type = union_type->data.unionation.tag_type;
5791 if (!type_has_bits(tag_type))5791 if (!type_has_bits(g, tag_type))
5792 return nullptr;5792 return nullptr;
57935793
5794 LLVMValueRef union_val = ir_llvm_value(g, instruction->value);5794 LLVMValueRef union_val = ir_llvm_value(g, instruction->value);
...@@ -5825,7 +5825,7 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutableGen *executable...@@ -5825,7 +5825,7 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutableGen *executable
5825 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);5825 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
5826 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);5826 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);
58275827
5828 if (get_codegen_ptr_type(operand_type) == nullptr) {5828 if (get_codegen_ptr_type_bail(g, operand_type) == nullptr) {
5829 return ZigLLVMBuildAtomicRMW(g->builder, op, ptr, operand, ordering, g->is_single_threaded);5829 return ZigLLVMBuildAtomicRMW(g->builder, op, ptr, operand, ordering, g->is_single_threaded);
5830 }5830 }
58315831
...@@ -5927,7 +5927,7 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutableGen *execu...@@ -5927,7 +5927,7 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutableGen *execu
5927{5927{
5928 ZigType *array_type = instruction->base.value->type;5928 ZigType *array_type = instruction->base.value->type;
5929 assert(array_type->id == ZigTypeIdArray);5929 assert(array_type->id == ZigTypeIdArray);
5930 assert(handle_is_ptr(array_type));5930 assert(handle_is_ptr(g, array_type));
5931 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);5931 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
5932 LLVMValueRef vector = ir_llvm_value(g, instruction->vector);5932 LLVMValueRef vector = ir_llvm_value(g, instruction->vector);
59335933
...@@ -5961,7 +5961,7 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutableGen *execu...@@ -5961,7 +5961,7 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutableGen *execu
5961{5961{
5962 ZigType *vector_type = instruction->base.value->type;5962 ZigType *vector_type = instruction->base.value->type;
5963 assert(vector_type->id == ZigTypeIdVector);5963 assert(vector_type->id == ZigTypeIdVector);
5964 assert(!handle_is_ptr(vector_type));5964 assert(!handle_is_ptr(g, vector_type));
5965 LLVMValueRef array_ptr = ir_llvm_value(g, instruction->array);5965 LLVMValueRef array_ptr = ir_llvm_value(g, instruction->array);
5966 LLVMTypeRef vector_type_ref = get_llvm_type(g, vector_type);5966 LLVMTypeRef vector_type_ref = get_llvm_type(g, vector_type);
59675967
...@@ -6057,7 +6057,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,...@@ -6057,7 +6057,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
6057{6057{
6058 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;6058 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
6059 LLVMValueRef their_result_ptr = nullptr;6059 LLVMValueRef their_result_ptr = nullptr;
6060 if (type_has_bits(result_type) && (non_async || result_loc != nullptr)) {6060 if (type_has_bits(g, result_type) && (non_async || result_loc != nullptr)) {
6061 LLVMValueRef their_result_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, frame_ret_start, "");6061 LLVMValueRef their_result_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, frame_ret_start, "");
6062 their_result_ptr = LLVMBuildLoad(g->builder, their_result_ptr_ptr, "");6062 their_result_ptr = LLVMBuildLoad(g->builder, their_result_ptr_ptr, "");
6063 if (result_loc != nullptr) {6063 if (result_loc != nullptr) {
...@@ -6082,7 +6082,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,...@@ -6082,7 +6082,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
6082 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,6082 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
6083 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");6083 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
6084 }6084 }
6085 if (non_async && type_has_bits(result_type)) {6085 if (non_async && type_has_bits(g, result_type)) {
6086 LLVMValueRef result_ptr = (result_loc == nullptr) ? their_result_ptr : result_loc;6086 LLVMValueRef result_ptr = (result_loc == nullptr) ? their_result_ptr : result_loc;
6087 return get_handle_value(g, result_ptr, result_type, ptr_result_type);6087 return get_handle_value(g, result_ptr, result_type, ptr_result_type);
6088 } else {6088 } else {
...@@ -6115,7 +6115,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutableGen *executable, IrI...@@ -6115,7 +6115,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutableGen *executable, IrI
6115 // This code is as if it is running inside the suspend block.6115 // This code is as if it is running inside the suspend block.
61166116
6117 // supply the awaiter return pointer6117 // supply the awaiter return pointer
6118 if (type_has_bits(result_type)) {6118 if (type_has_bits(g, result_type)) {
6119 LLVMValueRef awaiter_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, frame_ret_start + 1, "");6119 LLVMValueRef awaiter_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, frame_ret_start + 1, "");
6120 if (result_loc == nullptr) {6120 if (result_loc == nullptr) {
6121 // no copy needed6121 // no copy needed
...@@ -6599,7 +6599,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Zig...@@ -6599,7 +6599,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Zig
6599 }6599 }
66006600
6601 ZigType *type_entry = const_val->type;6601 ZigType *type_entry = const_val->type;
6602 assert(type_has_bits(type_entry));6602 assert(type_has_bits(g, type_entry));
6603 switch (type_entry->id) {6603 switch (type_entry->id) {
6604 case ZigTypeIdInvalid:6604 case ZigTypeIdInvalid:
6605 case ZigTypeIdMetaType:6605 case ZigTypeIdMetaType:
...@@ -6732,7 +6732,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha...@@ -6732,7 +6732,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha
6732 {6732 {
6733 ZigValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;6733 ZigValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;
6734 assert(array_const_val->type->id == ZigTypeIdArray);6734 assert(array_const_val->type->id == ZigTypeIdArray);
6735 if (!type_has_bits(array_const_val->type)) {6735 if (!type_has_bits(g, array_const_val->type)) {
6736 if (array_const_val->type->data.array.sentinel != nullptr) {6736 if (array_const_val->type->data.array.sentinel != nullptr) {
6737 ZigValue *pointee = array_const_val->type->data.array.sentinel;6737 ZigValue *pointee = array_const_val->type->data.array.sentinel;
6738 render_const_val(g, pointee, "");6738 render_const_val(g, pointee, "");
...@@ -6758,7 +6758,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha...@@ -6758,7 +6758,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha
6758 {6758 {
6759 ZigValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;6759 ZigValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;
6760 assert(struct_const_val->type->id == ZigTypeIdStruct);6760 assert(struct_const_val->type->id == ZigTypeIdStruct);
6761 if (!type_has_bits(struct_const_val->type)) {6761 if (!type_has_bits(g, struct_const_val->type)) {
6762 // make this a null pointer6762 // make this a null pointer
6763 ZigType *usize = g->builtin_types.entry_usize;6763 ZigType *usize = g->builtin_types.entry_usize;
6764 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),6764 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
...@@ -6777,7 +6777,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha...@@ -6777,7 +6777,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha
6777 {6777 {
6778 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_code.err_union_val;6778 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_code.err_union_val;
6779 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);6779 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
6780 if (!type_has_bits(err_union_const_val->type)) {6780 if (!type_has_bits(g, err_union_const_val->type)) {
6781 // make this a null pointer6781 // make this a null pointer
6782 ZigType *usize = g->builtin_types.entry_usize;6782 ZigType *usize = g->builtin_types.entry_usize;
6783 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),6783 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
...@@ -6793,7 +6793,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha...@@ -6793,7 +6793,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha
6793 {6793 {
6794 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_payload.err_union_val;6794 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_payload.err_union_val;
6795 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);6795 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
6796 if (!type_has_bits(err_union_const_val->type)) {6796 if (!type_has_bits(g, err_union_const_val->type)) {
6797 // make this a null pointer6797 // make this a null pointer
6798 ZigType *usize = g->builtin_types.entry_usize;6798 ZigType *usize = g->builtin_types.entry_usize;
6799 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),6799 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
...@@ -6809,7 +6809,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha...@@ -6809,7 +6809,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha
6809 {6809 {
6810 ZigValue *optional_const_val = const_val->data.x_ptr.data.base_optional_payload.optional_val;6810 ZigValue *optional_const_val = const_val->data.x_ptr.data.base_optional_payload.optional_val;
6811 assert(optional_const_val->type->id == ZigTypeIdOptional);6811 assert(optional_const_val->type->id == ZigTypeIdOptional);
6812 if (!type_has_bits(optional_const_val->type)) {6812 if (!type_has_bits(g, optional_const_val->type)) {
6813 // make this a null pointer6813 // make this a null pointer
6814 ZigType *usize = g->builtin_types.entry_usize;6814 ZigType *usize = g->builtin_types.entry_usize;
6815 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),6815 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
...@@ -6847,7 +6847,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n...@@ -6847,7 +6847,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n
6847 Error err;6847 Error err;
68486848
6849 ZigType *type_entry = const_val->type;6849 ZigType *type_entry = const_val->type;
6850 assert(type_has_bits(type_entry));6850 assert(type_has_bits(g, type_entry));
68516851
6852check: switch (const_val->special) {6852check: switch (const_val->special) {
6853 case ConstValSpecialLazy:6853 case ConstValSpecialLazy:
...@@ -6900,12 +6900,12 @@ check: switch (const_val->special) {...@@ -6900,12 +6900,12 @@ check: switch (const_val->special) {
6900 case ZigTypeIdOptional:6900 case ZigTypeIdOptional:
6901 {6901 {
6902 ZigType *child_type = type_entry->data.maybe.child_type;6902 ZigType *child_type = type_entry->data.maybe.child_type;
6903 if (!type_has_bits(child_type)) {6903 if (get_src_ptr_type(type_entry) != nullptr) {
6904 return LLVMConstInt(LLVMInt1Type(), const_val->data.x_optional ? 1 : 0, false);
6905 } else if (get_codegen_ptr_type(type_entry) != nullptr) {
6906 return gen_const_val_ptr(g, const_val, name);6904 return gen_const_val_ptr(g, const_val, name);
6907 } else if (child_type->id == ZigTypeIdErrorSet) {6905 } else if (child_type->id == ZigTypeIdErrorSet) {
6908 return gen_const_val_err_set(g, const_val, name);6906 return gen_const_val_err_set(g, const_val, name);
6907 } else if (!type_has_bits(g, child_type)) {
6908 return LLVMConstInt(LLVMInt1Type(), const_val->data.x_optional ? 1 : 0, false);
6909 } else {6909 } else {
6910 LLVMValueRef child_val;6910 LLVMValueRef child_val;
6911 LLVMValueRef maybe_val;6911 LLVMValueRef maybe_val;
...@@ -7128,7 +7128,7 @@ check: switch (const_val->special) {...@@ -7128,7 +7128,7 @@ check: switch (const_val->special) {
7128 LLVMValueRef union_value_ref;7128 LLVMValueRef union_value_ref;
7129 bool make_unnamed_struct;7129 bool make_unnamed_struct;
7130 ZigValue *payload_value = const_val->data.x_union.payload;7130 ZigValue *payload_value = const_val->data.x_union.payload;
7131 if (payload_value == nullptr || !type_has_bits(payload_value->type)) {7131 if (payload_value == nullptr || !type_has_bits(g, payload_value->type)) {
7132 if (type_entry->data.unionation.gen_tag_index == SIZE_MAX)7132 if (type_entry->data.unionation.gen_tag_index == SIZE_MAX)
7133 return LLVMGetUndef(get_llvm_type(g, type_entry));7133 return LLVMGetUndef(get_llvm_type(g, type_entry));
71347134
...@@ -7205,13 +7205,13 @@ check: switch (const_val->special) {...@@ -7205,13 +7205,13 @@ check: switch (const_val->special) {
7205 {7205 {
7206 ZigType *payload_type = type_entry->data.error_union.payload_type;7206 ZigType *payload_type = type_entry->data.error_union.payload_type;
7207 ZigType *err_set_type = type_entry->data.error_union.err_set_type;7207 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
7208 if (!type_has_bits(payload_type)) {7208 if (!type_has_bits(g, payload_type)) {
7209 assert(type_has_bits(err_set_type));7209 assert(type_has_bits(g, err_set_type));
7210 ErrorTableEntry *err_set = const_val->data.x_err_union.error_set->data.x_err_set;7210 ErrorTableEntry *err_set = const_val->data.x_err_union.error_set->data.x_err_set;
7211 uint64_t value = (err_set == nullptr) ? 0 : err_set->value;7211 uint64_t value = (err_set == nullptr) ? 0 : err_set->value;
7212 return LLVMConstInt(get_llvm_type(g, g->err_tag_type), value, false);7212 return LLVMConstInt(get_llvm_type(g, g->err_tag_type), value, false);
7213 } else if (!type_has_bits(err_set_type)) {7213 } else if (!type_has_bits(g, err_set_type)) {
7214 assert(type_has_bits(payload_type));7214 assert(type_has_bits(g, payload_type));
7215 return gen_const_val(g, const_val->data.x_err_union.payload, "");7215 return gen_const_val(g, const_val->data.x_err_union.payload, "");
7216 } else {7216 } else {
7217 LLVMValueRef err_tag_value;7217 LLVMValueRef err_tag_value;
...@@ -7445,7 +7445,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7445,7 +7445,7 @@ static void do_code_gen(CodeGen *g) {
7445 continue;7445 continue;
7446 }7446 }
74477447
7448 if (!type_has_bits(var->var_type))7448 if (!type_has_bits(g, var->var_type))
7449 continue;7449 continue;
74507450
7451 assert(var->decl_node);7451 assert(var->decl_node);
...@@ -7544,7 +7544,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7544,7 +7544,7 @@ static void do_code_gen(CodeGen *g) {
7544 } else {7544 } else {
7545 if (want_sret) {7545 if (want_sret) {
7546 g->cur_ret_ptr = LLVMGetParam(fn, 0);7546 g->cur_ret_ptr = LLVMGetParam(fn, 0);
7547 } else if (type_has_bits(fn_type_id->return_type)) {7547 } else if (type_has_bits(g, fn_type_id->return_type)) {
7548 g->cur_ret_ptr = build_alloca(g, fn_type_id->return_type, "result", 0);7548 g->cur_ret_ptr = build_alloca(g, fn_type_id->return_type, "result", 0);
7549 // TODO add debug info variable for this7549 // TODO add debug info variable for this
7550 } else {7550 } else {
...@@ -7609,7 +7609,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7609,7 +7609,7 @@ static void do_code_gen(CodeGen *g) {
7609 ZigType *child_type = ptr_type->data.pointer.child_type;7609 ZigType *child_type = ptr_type->data.pointer.child_type;
7610 if (type_resolve(g, child_type, ResolveStatusSizeKnown))7610 if (type_resolve(g, child_type, ResolveStatusSizeKnown))
7611 zig_unreachable();7611 zig_unreachable();
7612 if (!type_has_bits(child_type))7612 if (!type_has_bits(g, child_type))
7613 continue;7613 continue;
7614 if (instruction->base.base.ref_count == 0)7614 if (instruction->base.base.ref_count == 0)
7615 continue;7615 continue;
...@@ -7640,7 +7640,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7640,7 +7640,7 @@ static void do_code_gen(CodeGen *g) {
7640 for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) {7640 for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) {
7641 ZigVar *var = fn_table_entry->variable_list.at(var_i);7641 ZigVar *var = fn_table_entry->variable_list.at(var_i);
76427642
7643 if (!type_has_bits(var->var_type)) {7643 if (!type_has_bits(g, var->var_type)) {
7644 continue;7644 continue;
7645 }7645 }
7646 if (ir_get_var_is_comptime(var))7646 if (ir_get_var_is_comptime(var))
...@@ -7667,7 +7667,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7667,7 +7667,7 @@ static void do_code_gen(CodeGen *g) {
7667 FnGenParamInfo *gen_info = &fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index];7667 FnGenParamInfo *gen_info = &fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index];
7668 assert(gen_info->gen_index != SIZE_MAX);7668 assert(gen_info->gen_index != SIZE_MAX);
76697669
7670 if (handle_is_ptr(var->var_type)) {7670 if (handle_is_ptr(g, var->var_type)) {
7671 if (gen_info->is_byval) {7671 if (gen_info->is_byval) {
7672 gen_type = var->var_type;7672 gen_type = var->var_type;
7673 } else {7673 } else {
...@@ -7739,7 +7739,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7739,7 +7739,7 @@ static void do_code_gen(CodeGen *g) {
7739 LLVMValueRef resume_index_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, frame_resume_index, "");7739 LLVMValueRef resume_index_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, frame_resume_index, "");
7740 g->cur_async_resume_index_ptr = resume_index_ptr;7740 g->cur_async_resume_index_ptr = resume_index_ptr;
77417741
7742 if (type_has_bits(fn_type_id->return_type)) {7742 if (type_has_bits(g, fn_type_id->return_type)) {
7743 LLVMValueRef cur_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, frame_ret_start, "");7743 LLVMValueRef cur_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, frame_ret_start, "");
7744 g->cur_ret_ptr = LLVMBuildLoad(g->builder, cur_ret_ptr_ptr, "");7744 g->cur_ret_ptr = LLVMBuildLoad(g->builder, cur_ret_ptr_ptr, "");
7745 }7745 }
...@@ -9847,10 +9847,10 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu...@@ -9847,10 +9847,10 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
9847 case ZigTypeIdOptional:9847 case ZigTypeIdOptional:
9848 {9848 {
9849 ZigType *child_type = type_entry->data.maybe.child_type;9849 ZigType *child_type = type_entry->data.maybe.child_type;
9850 if (!type_has_bits(child_type)) {9850 if (!type_has_bits(g, child_type)) {
9851 buf_init_from_str(out_buf, "bool");9851 buf_init_from_str(out_buf, "bool");
9852 return;9852 return;
9853 } else if (type_is_nonnull_ptr(child_type)) {9853 } else if (type_is_nonnull_ptr(g, child_type)) {
9854 return get_c_type(g, gen_h, child_type, out_buf);9854 return get_c_type(g, gen_h, child_type, out_buf);
9855 } else {9855 } else {
9856 zig_unreachable();9856 zig_unreachable();
src/ir.cpp+78-55
...@@ -860,7 +860,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte...@@ -860,7 +860,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte
860 if (expected == actual)860 if (expected == actual)
861 return true;861 return true;
862862
863 if (get_codegen_ptr_type(expected) != nullptr && get_codegen_ptr_type(actual) != nullptr)863 if (get_src_ptr_type(expected) != nullptr && get_src_ptr_type(actual) != nullptr)
864 return true;864 return true;
865865
866 if (is_opt_err_set(expected) && is_opt_err_set(actual))866 if (is_opt_err_set(expected) && is_opt_err_set(actual))
...@@ -11399,7 +11399,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -11399,7 +11399,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11399 result.id = ConstCastResultIdInvalid;11399 result.id = ConstCastResultIdInvalid;
11400 return result;11400 return result;
11401 }11401 }
11402 if (type_has_bits(wanted_type) == type_has_bits(actual_type) &&11402 if (type_has_bits(g, wanted_type) == type_has_bits(g, actual_type) &&
11403 actual_ptr_type->data.pointer.bit_offset_in_host == wanted_ptr_type->data.pointer.bit_offset_in_host &&11403 actual_ptr_type->data.pointer.bit_offset_in_host == wanted_ptr_type->data.pointer.bit_offset_in_host &&
11404 actual_ptr_type->data.pointer.host_int_bytes == wanted_ptr_type->data.pointer.host_int_bytes &&11404 actual_ptr_type->data.pointer.host_int_bytes == wanted_ptr_type->data.pointer.host_int_bytes &&
11405 get_ptr_align(ira->codegen, actual_ptr_type) >= get_ptr_align(ira->codegen, wanted_ptr_type))11405 get_ptr_align(ira->codegen, actual_ptr_type) >= get_ptr_align(ira->codegen, wanted_ptr_type))
...@@ -12532,7 +12532,7 @@ static IrInstGen *ir_const_move(IrAnalyze *ira, IrInst *old_instruction, ZigValu...@@ -12532,7 +12532,7 @@ static IrInstGen *ir_const_move(IrAnalyze *ira, IrInst *old_instruction, ZigValu
12532static IrInstGen *ir_resolve_cast(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,12532static IrInstGen *ir_resolve_cast(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
12533 ZigType *wanted_type, CastOp cast_op)12533 ZigType *wanted_type, CastOp cast_op)
12534{12534{
12535 if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {12535 if (instr_is_comptime(value) || !type_has_bits(ira->codegen, wanted_type)) {
12536 IrInstGen *result = ir_const(ira, source_instr, wanted_type);12536 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12537 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type,12537 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type,
12538 result->value, wanted_type))12538 result->value, wanted_type))
...@@ -12918,7 +12918,7 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutableGen *exec, AstNo...@@ -12918,7 +12918,7 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutableGen *exec, AstNo
12918 case ConstValSpecialStatic:12918 case ConstValSpecialStatic:
12919 return ErrorNone;12919 return ErrorNone;
12920 case ConstValSpecialRuntime:12920 case ConstValSpecialRuntime:
12921 if (!type_has_bits(val->type))12921 if (!type_has_bits(codegen, val->type))
12922 return ErrorNone;12922 return ErrorNone;
1292312923
12924 exec_add_error_node_gen(codegen, exec, source_node,12924 exec_add_error_node_gen(codegen, exec, source_node,
...@@ -13082,7 +13082,11 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstGen *type_value) {...@@ -13082,7 +13082,11 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstGen *type_value) {
13082}13082}
1308313083
13084static Error ir_validate_vector_elem_type(IrAnalyze *ira, AstNode *source_node, ZigType *elem_type) {13084static Error ir_validate_vector_elem_type(IrAnalyze *ira, AstNode *source_node, ZigType *elem_type) {
13085 if (!is_valid_vector_elem_type(elem_type)) {13085 Error err;
13086 bool is_valid;
13087 if ((err = is_valid_vector_elem_type(ira->codegen, elem_type, &is_valid)))
13088 return err;
13089 if (!is_valid) {
13086 ir_add_error_node(ira, source_node,13090 ir_add_error_node(ira, source_node,
13087 buf_sprintf("vector element type must be integer, float, bool, or pointer; '%s' is invalid",13091 buf_sprintf("vector element type must be integer, float, bool, or pointer; '%s' is invalid",
13088 buf_ptr(&elem_type->name)));13092 buf_ptr(&elem_type->name)));
...@@ -13198,7 +13202,7 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,...@@ -13198,7 +13202,7 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
13198 return &const_instruction->base;13202 return &const_instruction->base;
13199 }13203 }
1320013204
13201 if (result_loc == nullptr && handle_is_ptr(wanted_type)) {13205 if (result_loc == nullptr && handle_is_ptr(ira->codegen, wanted_type)) {
13202 result_loc = no_result_loc();13206 result_loc = no_result_loc();
13203 }13207 }
13204 IrInstGen *result_loc_inst = nullptr;13208 IrInstGen *result_loc_inst = nullptr;
...@@ -13246,7 +13250,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins...@@ -13246,7 +13250,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins
13246 }13250 }
1324713251
13248 IrInstGen *result_loc_inst;13252 IrInstGen *result_loc_inst;
13249 if (handle_is_ptr(wanted_type)) {13253 if (handle_is_ptr(ira->codegen, wanted_type)) {
13250 if (result_loc == nullptr) result_loc = no_result_loc();13254 if (result_loc == nullptr) result_loc = no_result_loc();
13251 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);13255 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);
13252 if (type_is_invalid(result_loc_inst->value->type) ||13256 if (type_is_invalid(result_loc_inst->value->type) ||
...@@ -13358,7 +13362,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,...@@ -13358,7 +13362,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,
13358 }13362 }
1335913363
13360 IrInstGen *result_loc_inst;13364 IrInstGen *result_loc_inst;
13361 if (handle_is_ptr(wanted_type)) {13365 if (handle_is_ptr(ira->codegen, wanted_type)) {
13362 if (result_loc == nullptr) result_loc = no_result_loc();13366 if (result_loc == nullptr) result_loc = no_result_loc();
13363 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);13367 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);
13364 if (type_is_invalid(result_loc_inst->value->type) ||13368 if (type_is_invalid(result_loc_inst->value->type) ||
...@@ -13385,7 +13389,8 @@ static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr,...@@ -13385,7 +13389,8 @@ static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr,
1338513389
13386 IrInstGen *result = ir_const(ira, source_instr, wanted_type);13390 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
13387 result->value->special = ConstValSpecialStatic;13391 result->value->special = ConstValSpecialStatic;
13388 if (get_codegen_ptr_type(wanted_type) != nullptr) {13392
13393 if (get_src_ptr_type(wanted_type) != nullptr) {
13389 result->value->data.x_ptr.special = ConstPtrSpecialNull;13394 result->value->data.x_ptr.special = ConstPtrSpecialNull;
13390 } else if (is_opt_err_set(wanted_type)) {13395 } else if (is_opt_err_set(wanted_type)) {
13391 result->value->data.x_err_set = nullptr;13396 result->value->data.x_err_set = nullptr;
...@@ -13434,7 +13439,7 @@ static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInst...@@ -13434,7 +13439,7 @@ static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInst
13434 return ira->codegen->invalid_inst_gen;13439 return ira->codegen->invalid_inst_gen;
1343513440
13436 IrInstGen *result_loc;13441 IrInstGen *result_loc;
13437 if (type_has_bits(ptr_type) && !handle_is_ptr(elem_type)) {13442 if (type_has_bits(ira->codegen, ptr_type) && !handle_is_ptr(ira->codegen, elem_type)) {
13438 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), elem_type, nullptr, true, true);13443 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), elem_type, nullptr, true, true);
13439 } else {13444 } else {
13440 result_loc = nullptr;13445 result_loc = nullptr;
...@@ -13679,9 +13684,9 @@ static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_ins...@@ -13679,9 +13684,9 @@ static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_ins
13679 // If the destination integer type has no bits, then we can emit a comptime13684 // If the destination integer type has no bits, then we can emit a comptime
13680 // zero. However, we still want to emit a runtime safety check to make sure13685 // zero. However, we still want to emit a runtime safety check to make sure
13681 // the target is zero.13686 // the target is zero.
13682 if (!type_has_bits(wanted_type)) {13687 if (!type_has_bits(ira->codegen, wanted_type)) {
13683 assert(wanted_type->id == ZigTypeIdInt);13688 assert(wanted_type->id == ZigTypeIdInt);
13684 assert(type_has_bits(target->value->type));13689 assert(type_has_bits(ira->codegen, target->value->type));
13685 ir_build_assert_zero(ira, source_instr, target);13690 ir_build_assert_zero(ira, source_instr, target);
13686 IrInstGen *result = ir_const_unsigned(ira, source_instr, 0);13691 IrInstGen *result = ir_const_unsigned(ira, source_instr, 0);
13687 result->value->type = wanted_type;13692 result->value->type = wanted_type;
...@@ -15038,7 +15043,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns...@@ -15038,7 +15043,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
15038 }15043 }
1503915044
15040 IrInstGen *result_loc_inst;15045 IrInstGen *result_loc_inst;
15041 if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) {15046 if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(ira->codegen, child_type)) {
15042 if (result_loc == nullptr) result_loc = no_result_loc();15047 if (result_loc == nullptr) result_loc = no_result_loc();
15043 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true, true);15048 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true, true);
15044 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {15049 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
...@@ -15298,7 +15303,7 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn...@@ -15298,7 +15303,7 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn
15298 }15303 }
1529915304
15300 if (!instr_is_comptime(operand) && ira->explicit_return_type != nullptr &&15305 if (!instr_is_comptime(operand) && ira->explicit_return_type != nullptr &&
15301 handle_is_ptr(ira->explicit_return_type))15306 handle_is_ptr(ira->codegen, ira->explicit_return_type))
15302 {15307 {
15303 // result location mechanism took care of it.15308 // result location mechanism took care of it.
15304 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr);15309 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr);
...@@ -15387,7 +15392,7 @@ static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {...@@ -15387,7 +15392,7 @@ static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {
1538715392
15388static bool optional_value_is_null(ZigValue *val) {15393static bool optional_value_is_null(ZigValue *val) {
15389 assert(val->special == ConstValSpecialStatic);15394 assert(val->special == ConstValSpecialStatic);
15390 if (get_codegen_ptr_type(val->type) != nullptr) {15395 if (get_src_ptr_type(val->type) != nullptr) {
15391 if (val->data.x_ptr.special == ConstPtrSpecialNull) {15396 if (val->data.x_ptr.special == ConstPtrSpecialNull) {
15392 return true;15397 return true;
15393 } else if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {15398 } else if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
...@@ -15406,7 +15411,7 @@ static void set_optional_value_to_null(ZigValue *val) {...@@ -15406,7 +15411,7 @@ static void set_optional_value_to_null(ZigValue *val) {
15406 assert(val->special == ConstValSpecialStatic);15411 assert(val->special == ConstValSpecialStatic);
15407 if (val->type->id == ZigTypeIdNull) return; // nothing to do15412 if (val->type->id == ZigTypeIdNull) return; // nothing to do
15408 assert(val->type->id == ZigTypeIdOptional);15413 assert(val->type->id == ZigTypeIdOptional);
15409 if (get_codegen_ptr_type(val->type) != nullptr) {15414 if (get_src_ptr_type(val->type) != nullptr) {
15410 val->data.x_ptr.special = ConstPtrSpecialNull;15415 val->data.x_ptr.special = ConstPtrSpecialNull;
15411 } else if (is_opt_err_set(val->type)) {15416 } else if (is_opt_err_set(val->type)) {
15412 val->data.x_err_set = nullptr;15417 val->data.x_err_set = nullptr;
...@@ -16244,7 +16249,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i...@@ -16244,7 +16249,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
16244 operator_allowed = false;16249 operator_allowed = false;
16245 break;16250 break;
16246 case ZigTypeIdOptional:16251 case ZigTypeIdOptional:
16247 operator_allowed = is_equality_cmp && get_codegen_ptr_type(resolved_type) != nullptr;16252 operator_allowed = is_equality_cmp && get_src_ptr_type(resolved_type) != nullptr;
16248 break;16253 break;
16249 }16254 }
16250 if (!operator_allowed) {16255 if (!operator_allowed) {
...@@ -17894,7 +17899,7 @@ static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,...@@ -17894,7 +17899,7 @@ static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
17894 if (!exec_has_err_ret_trace(ira->codegen, ira->old_irb.exec)) {17899 if (!exec_has_err_ret_trace(ira->codegen, ira->old_irb.exec)) {
17895 IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type);17900 IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type);
17896 ZigValue *out_val = result->value;17901 ZigValue *out_val = result->value;
17897 assert(get_codegen_ptr_type(optional_type) != nullptr);17902 assert(get_src_ptr_type(optional_type) != nullptr);
17898 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;17903 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
17899 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;17904 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;
17900 return result;17905 return result;
...@@ -18283,7 +18288,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -18283,7 +18288,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
18283 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {18288 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
18284 return ira->codegen->invalid_inst_gen;18289 return ira->codegen->invalid_inst_gen;
18285 }18290 }
18286 if (!type_has_bits(value_type)) {18291 if (!type_has_bits(ira->codegen, value_type)) {
18287 parent_ptr_align = 0;18292 parent_ptr_align = 0;
18288 }18293 }
18289 // If we're casting from a sentinel-terminated array to a non-sentinel-terminated array,18294 // If we're casting from a sentinel-terminated array to a non-sentinel-terminated array,
...@@ -18328,7 +18333,10 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -18328,7 +18333,10 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
18328 if (type_is_invalid(dest_type))18333 if (type_is_invalid(dest_type))
18329 return ira->codegen->invalid_inst_gen;18334 return ira->codegen->invalid_inst_gen;
1833018335
18331 if (get_codegen_ptr_type(dest_type) != nullptr) {18336 ZigType *dest_cg_ptr_type;
18337 if ((err = get_codegen_ptr_type(ira->codegen, dest_type, &dest_cg_ptr_type)))
18338 return ira->codegen->invalid_inst_gen;
18339 if (dest_cg_ptr_type != nullptr) {
18332 ir_add_error(ira, &result_loc->source_instruction->base,18340 ir_add_error(ira, &result_loc->source_instruction->base,
18333 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));18341 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));
18334 return ira->codegen->invalid_inst_gen;18342 return ira->codegen->invalid_inst_gen;
...@@ -18340,7 +18348,10 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -18340,7 +18348,10 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
18340 return ira->codegen->invalid_inst_gen;18348 return ira->codegen->invalid_inst_gen;
18341 }18349 }
1834218350
18343 if (get_codegen_ptr_type(value_type) != nullptr) {18351 ZigType *value_cg_ptr_type;
18352 if ((err = get_codegen_ptr_type(ira->codegen, value_type, &value_cg_ptr_type)))
18353 return ira->codegen->invalid_inst_gen;
18354 if (value_cg_ptr_type != nullptr) {
18344 ir_add_error(ira, suspend_source_instr,18355 ir_add_error(ira, suspend_source_instr,
18345 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name)));18356 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name)));
18346 return ira->codegen->invalid_inst_gen;18357 return ira->codegen->invalid_inst_gen;
...@@ -18400,7 +18411,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -18400,7 +18411,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
18400 }18411 }
18401 }18412 }
18402 uint64_t parent_ptr_align = 0;18413 uint64_t parent_ptr_align = 0;
18403 if (type_has_bits(value_type)) parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);18414 if (type_has_bits(ira->codegen, value_type)) parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
18404 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,18415 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
18405 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,18416 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
18406 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);18417 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
...@@ -19118,7 +19129,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19118,7 +19129,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19118 }19129 }
1911919130
19120 IrInstGen *first_arg;19131 IrInstGen *first_arg;
19121 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {19132 if (!first_arg_known_bare && handle_is_ptr(ira->codegen, first_arg_ptr->value->type->data.pointer.child_type)) {
19122 first_arg = first_arg_ptr;19133 first_arg = first_arg_ptr;
19123 } else {19134 } else {
19124 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);19135 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
...@@ -19247,7 +19258,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19247,7 +19258,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19247 }19258 }
1924819259
19249 IrInstGen *first_arg;19260 IrInstGen *first_arg;
19250 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {19261 if (!first_arg_known_bare && handle_is_ptr(ira->codegen, first_arg_ptr->value->type->data.pointer.child_type)) {
19251 first_arg = first_arg_ptr;19262 first_arg = first_arg_ptr;
19252 } else {19263 } else {
19253 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);19264 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
...@@ -19366,7 +19377,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19366,7 +19377,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19366 }19377 }
1936719378
19368 IrInstGen *result_loc;19379 IrInstGen *result_loc;
19369 if (handle_is_ptr(impl_fn_type_id->return_type)) {19380 if (handle_is_ptr(ira->codegen, impl_fn_type_id->return_type)) {
19370 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,19381 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
19371 impl_fn_type_id->return_type, nullptr, true, false);19382 impl_fn_type_id->return_type, nullptr, true, false);
19372 if (result_loc != nullptr) {19383 if (result_loc != nullptr) {
...@@ -19383,7 +19394,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19383,7 +19394,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19383 if (res_child_type == ira->codegen->builtin_types.entry_var) {19394 if (res_child_type == ira->codegen->builtin_types.entry_var) {
19384 res_child_type = impl_fn_type_id->return_type;19395 res_child_type = impl_fn_type_id->return_type;
19385 }19396 }
19386 if (!handle_is_ptr(res_child_type)) {19397 if (!handle_is_ptr(ira->codegen, res_child_type)) {
19387 ir_reset_result(call_result_loc);19398 ir_reset_result(call_result_loc);
19388 result_loc = nullptr;19399 result_loc = nullptr;
19389 }19400 }
...@@ -19435,7 +19446,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19435,7 +19446,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1943519446
19436 IrInstGen *first_arg;19447 IrInstGen *first_arg;
19437 if (param_type->id == ZigTypeIdPointer &&19448 if (param_type->id == ZigTypeIdPointer &&
19438 handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type))19449 handle_is_ptr(ira->codegen, first_arg_ptr->value->type->data.pointer.child_type))
19439 {19450 {
19440 first_arg = first_arg_ptr;19451 first_arg = first_arg_ptr;
19441 } else {19452 } else {
...@@ -19504,7 +19515,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19504,7 +19515,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19504 }19515 }
1950519516
19506 IrInstGen *result_loc;19517 IrInstGen *result_loc;
19507 if (handle_is_ptr(return_type)) {19518 if (handle_is_ptr(ira->codegen, return_type)) {
19508 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,19519 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
19509 return_type, nullptr, true, false);19520 return_type, nullptr, true, false);
19510 if (result_loc != nullptr) {19521 if (result_loc != nullptr) {
...@@ -19521,7 +19532,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19521,7 +19532,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19521 if (res_child_type == ira->codegen->builtin_types.entry_var) {19532 if (res_child_type == ira->codegen->builtin_types.entry_var) {
19522 res_child_type = return_type;19533 res_child_type = return_type;
19523 }19534 }
19524 if (!handle_is_ptr(res_child_type)) {19535 if (!handle_is_ptr(ira->codegen, res_child_type)) {
19525 ir_reset_result(call_result_loc);19536 ir_reset_result(call_result_loc);
19526 result_loc = nullptr;19537 result_loc = nullptr;
19527 }19538 }
...@@ -23346,7 +23357,7 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,...@@ -23346,7 +23357,7 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,
23346 return nullptr;23357 return nullptr;
23347 }23358 }
2334823359
23349 if (!type_has_bits(field->type_entry)) {23360 if (!type_has_bits(ira->codegen, field->type_entry)) {
23350 ir_add_error(ira, &field_name_value->base,23361 ir_add_error(ira, &field_name_value->base,
23351 buf_sprintf("zero-bit field '%s' in struct '%s' has no offset",23362 buf_sprintf("zero-bit field '%s' in struct '%s' has no offset",
23352 buf_ptr(field_name), buf_ptr(&container_type->name)));23363 buf_ptr(field_name), buf_ptr(&container_type->name)));
...@@ -24264,7 +24275,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -24264,7 +24275,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24264 return ErrorSemanticAnalyzeFail;24275 return ErrorSemanticAnalyzeFail;
24265 if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown)))24276 if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown)))
24266 return err;24277 return err;
24267 if (!type_has_bits(struct_field->type_entry)) {24278 if (!type_has_bits(ira->codegen, struct_field->type_entry)) {
24268 inner_fields[1]->data.x_optional = nullptr;24279 inner_fields[1]->data.x_optional = nullptr;
24269 } else {24280 } else {
24270 size_t byte_offset = struct_field->offset;24281 size_t byte_offset = struct_field->offset;
...@@ -25077,7 +25088,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch...@@ -25077,7 +25088,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
2507725088
25078 ZigType *result_type = get_optional_type(ira->codegen, operand_type);25089 ZigType *result_type = get_optional_type(ira->codegen, operand_type);
25079 IrInstGen *result_loc;25090 IrInstGen *result_loc;
25080 if (handle_is_ptr(result_type)) {25091 if (handle_is_ptr(ira->codegen, result_type)) {
25081 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,25092 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
25082 result_type, nullptr, true, true);25093 result_type, nullptr, true, true);
25083 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {25094 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
...@@ -25396,8 +25407,11 @@ static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVe...@@ -25396,8 +25407,11 @@ static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVe
25396static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr,25407static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr,
25397 ZigType *scalar_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)25408 ZigType *scalar_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)
25398{25409{
25410 Error err;
25399 ir_assert(source_instr && scalar_type && a && b && mask, source_instr);25411 ir_assert(source_instr && scalar_type && a && b && mask, source_instr);
25400 ir_assert(is_valid_vector_elem_type(scalar_type), source_instr);25412
25413 if ((err = ir_validate_vector_elem_type(ira, source_instr->source_node, scalar_type)))
25414 return ira->codegen->invalid_inst_gen;
2540125415
25402 uint32_t len_mask;25416 uint32_t len_mask;
25403 if (mask->value->type->id == ZigTypeIdVector) {25417 if (mask->value->type->id == ZigTypeIdVector) {
...@@ -27364,7 +27378,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -27364,7 +27378,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
27364 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown)))27378 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown)))
27365 return ira->codegen->invalid_inst_gen;27379 return ira->codegen->invalid_inst_gen;
2736627380
27367 if (type_has_bits(dest_type) && !type_has_bits(src_type) && safety_check_on) {27381 if (type_has_bits(ira->codegen, dest_type) && !type_has_bits(ira->codegen, src_type) && safety_check_on) {
27368 ErrorMsg *msg = ir_add_error(ira, source_instr,27382 ErrorMsg *msg = ir_add_error(ira, source_instr,
27369 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",27383 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",
27370 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));27384 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));
...@@ -27423,7 +27437,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -27423,7 +27437,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2742327437
27424 // Keep the bigger alignment, it can only help-27438 // Keep the bigger alignment, it can only help-
27425 // unless the target is zero bits.27439 // unless the target is zero bits.
27426 if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) {27440 if (src_align_bytes > dest_align_bytes && type_has_bits(ira->codegen, dest_type)) {
27427 result = ir_align_cast(ira, result, src_align_bytes, false);27441 result = ir_align_cast(ira, result, src_align_bytes, false);
27428 }27442 }
2742927443
...@@ -27444,7 +27458,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -27444,7 +27458,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
27444 // Keep the bigger alignment, it can only help-27458 // Keep the bigger alignment, it can only help-
27445 // unless the target is zero bits.27459 // unless the target is zero bits.
27446 IrInstGen *result;27460 IrInstGen *result;
27447 if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) {27461 if (src_align_bytes > dest_align_bytes && type_has_bits(ira->codegen, dest_type)) {
27448 result = ir_align_cast(ira, casted_ptr, src_align_bytes, false);27462 result = ir_align_cast(ira, casted_ptr, src_align_bytes, false);
27449 if (type_is_invalid(result->value->type))27463 if (type_is_invalid(result->value->type))
27450 return ira->codegen->invalid_inst_gen;27464 return ira->codegen->invalid_inst_gen;
...@@ -27802,9 +27816,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -27802,9 +27816,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
27802 Error err;27816 Error err;
2780327817
27804 ZigType *src_type = value->value->type;27818 ZigType *src_type = value->value->type;
27805 ir_assert(get_codegen_ptr_type(src_type) == nullptr, source_instr);
27806 ir_assert(type_can_bit_cast(src_type), source_instr);27819 ir_assert(type_can_bit_cast(src_type), source_instr);
27807 ir_assert(get_codegen_ptr_type(dest_type) == nullptr, source_instr);
27808 ir_assert(type_can_bit_cast(dest_type), source_instr);27820 ir_assert(type_can_bit_cast(dest_type), source_instr);
2780927821
27810 if (dest_type->id == ZigTypeIdEnum) {27822 if (dest_type->id == ZigTypeIdEnum) {
...@@ -27863,7 +27875,7 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir...@@ -27863,7 +27875,7 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir
27863 Error err;27875 Error err;
2786427876
27865 ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr);27877 ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr);
27866 ir_assert(type_has_bits(ptr_type), source_instr);27878 ir_assert(type_has_bits(ira->codegen, ptr_type), source_instr);
2786727879
27868 IrInstGen *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);27880 IrInstGen *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);
27869 if (type_is_invalid(casted_int->value->type))27881 if (type_is_invalid(casted_int->value->type))
...@@ -27981,7 +27993,7 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr...@@ -27981,7 +27993,7 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr
27981 if (!val)27993 if (!val)
27982 return ira->codegen->invalid_inst_gen;27994 return ira->codegen->invalid_inst_gen;
2798327995
27984 // Since we've already run this type trough get_codegen_ptr_type it is27996 // Since we've already run this type trough get_src_ptr_type it is
27985 // safe to access the x_ptr fields27997 // safe to access the x_ptr fields
27986 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {27998 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
27987 IrInstGen *result = ir_const(ira, &instruction->base.base, usize);27999 IrInstGen *result = ir_const(ira, &instruction->base.base, usize);
...@@ -28232,10 +28244,17 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {...@@ -28232,10 +28244,17 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
28232 max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count));28244 max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count));
28233 return ira->codegen->builtin_types.entry_invalid;28245 return ira->codegen->builtin_types.entry_invalid;
28234 }28246 }
28235 } else if (get_codegen_ptr_type(operand_type) == nullptr) {28247 } else {
28236 ir_add_error(ira, &op->base,28248 Error err;
28237 buf_sprintf("expected integer, float, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));28249 ZigType *operand_ptr_type;
28238 return ira->codegen->builtin_types.entry_invalid;28250 if ((err = get_codegen_ptr_type(ira->codegen, operand_type, &operand_ptr_type)))
28251 return ira->codegen->builtin_types.entry_invalid;
28252 if (operand_ptr_type == nullptr) {
28253 ir_add_error(ira, &op->base,
28254 buf_sprintf("expected integer, float, enum or pointer type, found '%s'",
28255 buf_ptr(&operand_type->name)));
28256 return ira->codegen->builtin_types.entry_invalid;
28257 }
28239 }28258 }
2824028259
28241 return operand_type;28260 return operand_type;
...@@ -28666,15 +28685,19 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i...@@ -28666,15 +28685,19 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
28666 if (type_is_invalid(uncasted_op->value->type))28685 if (type_is_invalid(uncasted_op->value->type))
28667 return ira->codegen->invalid_inst_gen;28686 return ira->codegen->invalid_inst_gen;
2866828687
28669 uint32_t vector_len; // UINT32_MAX means not a vector28688 uint32_t vector_len = UINT32_MAX; // means not a vector
28670 if (uncasted_op->value->type->id == ZigTypeIdArray &&28689 if (uncasted_op->value->type->id == ZigTypeIdArray) {
28671 is_valid_vector_elem_type(uncasted_op->value->type->data.array.child_type))28690 bool can_be_vec_elem;
28672 {28691 if ((err = is_valid_vector_elem_type(ira->codegen, uncasted_op->value->type->data.array.child_type,
28673 vector_len = uncasted_op->value->type->data.array.len;28692 &can_be_vec_elem)))
28693 {
28694 return ira->codegen->invalid_inst_gen;
28695 }
28696 if (can_be_vec_elem) {
28697 vector_len = uncasted_op->value->type->data.array.len;
28698 }
28674 } else if (uncasted_op->value->type->id == ZigTypeIdVector) {28699 } else if (uncasted_op->value->type->id == ZigTypeIdVector) {
28675 vector_len = uncasted_op->value->type->data.vector.len;28700 vector_len = uncasted_op->value->type->data.vector.len;
28676 } else {
28677 vector_len = UINT32_MAX;
28678 }28701 }
2867928702
28680 bool is_vector = (vector_len != UINT32_MAX);28703 bool is_vector = (vector_len != UINT32_MAX);
...@@ -29075,7 +29098,7 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i...@@ -29075,7 +29098,7 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i
29075 }29098 }
2907629099
29077 IrInstGen *result_loc;29100 IrInstGen *result_loc;
29078 if (type_has_bits(result_type)) {29101 if (type_has_bits(ira->codegen, result_type)) {
29079 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,29102 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
29080 result_type, nullptr, true, true);29103 result_type, nullptr, true, true);
29081 if (result_loc != nullptr &&29104 if (result_loc != nullptr &&
...@@ -29125,7 +29148,7 @@ static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSp...@@ -29125,7 +29148,7 @@ static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSp
29125 if (type_is_invalid(operand->value->type))29148 if (type_is_invalid(operand->value->type))
29126 return ira->codegen->invalid_inst_gen;29149 return ira->codegen->invalid_inst_gen;
2912729150
29128 if (!type_has_bits(operand->value->type))29151 if (!type_has_bits(ira->codegen, operand->value->type))
29129 return ir_const_void(ira, &instruction->base.base);29152 return ir_const_void(ira, &instruction->base.base);
2913029153
29131 switch (instruction->spill_id) {29154 switch (instruction->spill_id) {
...@@ -29145,7 +29168,7 @@ static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpil...@@ -29145,7 +29168,7 @@ static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpil
29145 return ira->codegen->invalid_inst_gen;29168 return ira->codegen->invalid_inst_gen;
2914629169
29147 if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope) ||29170 if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope) ||
29148 !type_has_bits(operand->value->type) ||29171 !type_has_bits(ira->codegen, operand->value->type) ||
29149 instr_is_comptime(operand))29172 instr_is_comptime(operand))
29150 {29173 {
29151 return operand;29174 return operand;
...@@ -30188,7 +30211,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -30188,7 +30211,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
30188 if (align_bytes != 0) {30211 if (align_bytes != 0) {
30189 if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusAlignmentKnown)))30212 if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusAlignmentKnown)))
30190 return err;30213 return err;
30191 if (!type_has_bits(elem_type))30214 if (!type_has_bits(ira->codegen, elem_type))
30192 align_bytes = 0;30215 align_bytes = 0;
30193 }30216 }
30194 bool allow_zero = lazy_ptr_type->is_allowzero || lazy_ptr_type->ptr_len == PtrLenC;30217 bool allow_zero = lazy_ptr_type->is_allowzero || lazy_ptr_type->ptr_len == PtrLenC;
test/stage1/behavior/cast.zig+7
...@@ -786,3 +786,10 @@ test "cast between C pointer with different but compatible types" {...@@ -786,3 +786,10 @@ test "cast between C pointer with different but compatible types" {
786 };786 };
787 S.doTheTest();787 S.doTheTest();
788}788}
789
790var global_struct: struct { f0: usize } = undefined;
791
792test "assignment to optional pointer result loc" {
793 var foo: struct { ptr: ?*c_void } = .{ .ptr = &global_struct };
794 expect(foo.ptr.? == @ptrCast(*c_void, &global_struct));
795}