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
597597 entry->size_in_bits = SIZE_MAX;
598598 entry->abi_align = UINT32_MAX;
599599 } else if (type_is_resolved(child_type, ResolveStatusZeroBitsKnown)) {
600 if (type_has_bits(child_type)) {
600 if (type_has_bits(g, child_type)) {
601601 entry->abi_size = g->builtin_types.entry_usize->abi_size;
602602 entry->size_in_bits = g->builtin_types.entry_usize->size_in_bits;
603603 entry->abi_align = g->builtin_types.entry_usize->abi_align;
......@@ -660,11 +660,11 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
660660 buf_resize(&entry->name, 0);
661661 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)) {
664664 entry->size_in_bits = g->builtin_types.entry_bool->size_in_bits;
665665 entry->abi_size = g->builtin_types.entry_bool->abi_size;
666666 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) {
668668 // This is an optimization but also is necessary for calling C
669669 // functions where all pointers are optional pointers.
670670 // Function types are technically pointers.
......@@ -729,8 +729,8 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa
729729 entry->data.error_union.err_set_type = err_set_type;
730730 entry->data.error_union.payload_type = payload_type;
731731
732 if (!type_has_bits(payload_type)) {
733 if (type_has_bits(err_set_type)) {
732 if (!type_has_bits(g, payload_type)) {
733 if (type_has_bits(g, err_set_type)) {
734734 entry->size_in_bits = err_set_type->size_in_bits;
735735 entry->abi_size = err_set_type->abi_size;
736736 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
739739 entry->abi_size = 0;
740740 entry->abi_align = 0;
741741 }
742 } else if (!type_has_bits(err_set_type)) {
742 } else if (!type_has_bits(g, err_set_type)) {
743743 entry->size_in_bits = payload_type->size_in_bits;
744744 entry->abi_size = payload_type->abi_size;
745745 entry->abi_align = payload_type->abi_align;
......@@ -856,13 +856,13 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
856856 entry->data.structure.requires_comptime = true;
857857 }
858858
859 if (!type_has_bits(ptr_type)) {
859 if (!type_has_bits(g, ptr_type)) {
860860 entry->data.structure.gen_field_count = 1;
861861 entry->data.structure.fields[slice_ptr_index]->gen_index = SIZE_MAX;
862862 entry->data.structure.fields[slice_len_index]->gen_index = 0;
863863 }
864864
865 if (type_has_bits(ptr_type)) {
865 if (type_has_bits(g, ptr_type)) {
866866 entry->size_in_bits = ptr_type->size_in_bits + g->builtin_types.entry_usize->size_in_bits;
867867 entry->abi_size = ptr_type->abi_size + g->builtin_types.entry_usize->abi_size;
868868 entry->abi_align = ptr_type->abi_align;
......@@ -969,12 +969,12 @@ ZigType *get_stack_trace_type(CodeGen *g) {
969969
970970bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id) {
971971 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);
973973 }
974974 if (fn_type_id->cc != CallingConventionC) {
975975 return false;
976976 }
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)) {
978978 return false;
979979 }
980980 if (g->zig_target->arch == ZigLLVM_x86 ||
......@@ -1650,15 +1650,16 @@ static Error emit_error_unless_type_allowed_in_packed_container(CodeGen *g, ZigT
16501650 return ErrorSemanticAnalyzeFail;
16511651 }
16521652 zig_unreachable();
1653 case ZigTypeIdOptional:
1654 if (get_codegen_ptr_type(type_entry) != nullptr) {
1655 return ErrorNone;
1656 } else {
1657 add_node_error(g, source_node,
1658 buf_sprintf("type '%s' not allowed in packed %s; no guaranteed in-memory representation",
1659 buf_ptr(&type_entry->name), container_name));
1660 return ErrorSemanticAnalyzeFail;
1661 }
1653 case ZigTypeIdOptional: {
1654 ZigType *ptr_type;
1655 if ((err = get_codegen_ptr_type(g, type_entry, &ptr_type))) return err;
1656 if (ptr_type != nullptr) return ErrorNone;
1657
1658 add_node_error(g, source_node,
1659 buf_sprintf("type '%s' not allowed in packed %s; no guaranteed in-memory representation",
1660 buf_ptr(&type_entry->name), container_name));
1661 return ErrorSemanticAnalyzeFail;
1662 }
16621663 case ZigTypeIdEnum: {
16631664 AstNode *decl_node = type_entry->data.enumeration.decl_node;
16641665 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) {
17371738 case ZigTypeIdPointer:
17381739 if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))
17391740 return err;
1740 if (!type_has_bits(type_entry)) {
1741 if (!type_has_bits(g, type_entry)) {
17411742 *result = false;
17421743 return ErrorNone;
17431744 }
......@@ -1753,7 +1754,7 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {
17531754 *result = false;
17541755 return ErrorNone;
17551756 }
1756 if (!type_is_nonnull_ptr(child_type)) {
1757 if (!type_is_nonnull_ptr(g, child_type)) {
17571758 *result = false;
17581759 return ErrorNone;
17591760 }
......@@ -1848,7 +1849,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
18481849 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
18491850 if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))
18501851 return g->builtin_types.entry_invalid;
1851 if (!type_has_bits(type_entry)) {
1852 if (!type_has_bits(g, type_entry)) {
18521853 add_node_error(g, param_node->data.param_decl.type,
18531854 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",
18541855 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
20822083 field->src_index = i;
20832084 field->align = fields[i].align;
20842085
2085 if (type_has_bits(field->type_entry)) {
2086 if (type_has_bits(g, field->type_entry)) {
20862087 assert(type_is_resolved(field->type_entry, ResolveStatusSizeKnown));
20872088 unsigned field_abi_align = max(field->align, field->type_entry->abi_align);
20882089 if (field_abi_align > abi_align) {
......@@ -2097,7 +2098,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel
20972098 size_t next_offset = 0;
20982099 for (size_t i = 0; i < field_count; i += 1) {
20992100 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))
21012102 continue;
21022103
21032104 field->offset = next_offset;
......@@ -2105,7 +2106,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel
21052106 // find the next non-zero-byte field for offset calculations
21062107 size_t next_src_field_index = i + 1;
21072108 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))
21092110 break;
21102111 }
21112112 size_t next_abi_align;
......@@ -2402,7 +2403,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {
24022403 union_type->data.unionation.most_aligned_union_member = most_aligned_union_member;
24032404
24042405 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)) {
24062407 if ((err = type_resolve(g, tag_type, ResolveStatusAlignmentKnown))) {
24072408 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
24082409 return ErrorSemanticAnalyzeFail;
......@@ -2504,7 +2505,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
25042505 if (type_is_invalid(union_type))
25052506 return ErrorSemanticAnalyzeFail;
25062507
2507 if (!type_has_bits(field_type))
2508 if (!type_has_bits(g, field_type))
25082509 continue;
25092510
25102511 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) {
25232524 union_type->data.unionation.union_abi_size = union_abi_size;
25242525
25252526 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)) {
25272528 if ((err = type_resolve(g, tag_type, ResolveStatusSizeKnown))) {
25282529 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
25292530 return ErrorSemanticAnalyzeFail;
......@@ -2998,7 +2999,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {
29982999 }
29993000 }
30003001
3001 if (!type_has_bits(struct_type)) {
3002 if (!type_has_bits(g, struct_type)) {
30023003 assert(struct_type->abi_align == 0);
30033004 }
30043005
......@@ -4416,15 +4417,50 @@ ZigType *get_src_ptr_type(ZigType *type) {
44164417 return nullptr;
44174418}
44184419
4419ZigType *get_codegen_ptr_type(ZigType *type) {
4420Error get_codegen_ptr_type(CodeGen *g, ZigType *type, ZigType **result) {
4421 Error err;
4422
44204423 ZigType *ty = get_src_ptr_type(type);
4421 if (ty == nullptr || !type_has_bits(ty))
4422 return nullptr;
4423 return ty;
4424 if (ty == nullptr) {
4425 *result = nullptr;
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;
44244438}
44254439
4426bool type_is_nonnull_ptr(ZigType *type) {
4427 return get_codegen_ptr_type(type) == type && !ptr_allows_addr_zero(type);
4440ZigType *get_codegen_ptr_type_bail(CodeGen *g, ZigType *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;
44284464}
44294465
44304466static 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) {
44994535 }
45004536
45014537 bool is_noalias = param_info->is_noalias;
4502 if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) {
4503 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
4538 if (is_noalias) {
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 }
45044544 }
45054545
45064546 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) {
45094549 fn_table_entry->child_scope = var->child_scope;
45104550 var->shadowable = var->shadowable || is_var_args;
45114551
4512 if (type_has_bits(param_type)) {
4552 if (type_has_bits(g, param_type)) {
45134553 fn_table_entry->variable_list.append(var);
45144554 }
45154555 }
......@@ -5027,15 +5067,35 @@ ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
50275067 return new_entry;
50285068}
50295069
5030bool is_valid_vector_elem_type(ZigType *elem_type) {
5031 return elem_type->id == ZigTypeIdInt ||
5070Error is_valid_vector_elem_type(CodeGen *g, ZigType *elem_type, bool *result) {
5071 if (elem_type->id == ZigTypeIdInt ||
50325072 elem_type->id == ZigTypeIdFloat ||
5033 elem_type->id == ZigTypeIdBool ||
5034 get_codegen_ptr_type(elem_type) != nullptr;
5073 elem_type->id == ZigTypeIdBool)
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;
50355089}
50365090
50375091ZigType *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
50405100 TypeId type_id = {};
50415101 type_id.id = ZigTypeIdVector;
......@@ -5049,7 +5109,7 @@ ZigType *get_vector_type(CodeGen *g, uint32_t len, ZigType *elem_type) {
50495109 }
50505110
50515111 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)) {
50535113 // Vectors can only be ints, floats, bools, or pointers. ints (inc. bools) and floats have trivially resolvable
50545114 // llvm type refs. pointers we will use usize instead.
50555115 LLVMTypeRef example_vector_llvm_type;
......@@ -5081,7 +5141,7 @@ ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type) {
50815141 return *get_c_int_type_ptr(g, c_int_type);
50825142}
50835143
5084bool handle_is_ptr(ZigType *type_entry) {
5144bool handle_is_ptr(CodeGen *g, ZigType *type_entry) {
50855145 switch (type_entry->id) {
50865146 case ZigTypeIdInvalid:
50875147 case ZigTypeIdMetaType:
......@@ -5108,15 +5168,15 @@ bool handle_is_ptr(ZigType *type_entry) {
51085168 case ZigTypeIdArray:
51095169 case ZigTypeIdStruct:
51105170 case ZigTypeIdFnFrame:
5111 return type_has_bits(type_entry);
5171 return type_has_bits(g, type_entry);
51125172 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);
51145174 case ZigTypeIdOptional:
5115 return type_has_bits(type_entry->data.maybe.child_type) &&
5116 !type_is_nonnull_ptr(type_entry->data.maybe.child_type) &&
5175 return type_has_bits(g, type_entry->data.maybe.child_type) &&
5176 !type_is_nonnull_ptr(g, type_entry->data.maybe.child_type) &&
51175177 type_entry->data.maybe.child_type->id != ZigTypeIdErrorSet;
51185178 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
51215181 }
51225182 zig_unreachable();
......@@ -5329,7 +5389,7 @@ static uint32_t hash_const_val(ZigValue *const_val) {
53295389 // TODO better hashing algorithm
53305390 return 2709806591;
53315391 case ZigTypeIdOptional:
5332 if (get_codegen_ptr_type(const_val->type) != nullptr) {
5392 if (get_src_ptr_type(const_val->type) != nullptr) {
53335393 return hash_const_val_ptr(const_val) * 1992916303;
53345394 } else if (const_val->type->data.maybe.child_type->id == ZigTypeIdErrorSet) {
53355395 return hash_const_val_error_set(const_val) * 3147031929;
......@@ -5455,7 +5515,7 @@ static bool can_mutate_comptime_var_state(ZigValue *value) {
54555515 return false;
54565516
54575517 case ZigTypeIdOptional:
5458 if (get_codegen_ptr_type(value->type) != nullptr)
5518 if (get_src_ptr_type(value->type) != nullptr)
54595519 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;
54605520 if (value->data.x_optional == nullptr)
54615521 return false;
......@@ -5593,11 +5653,13 @@ bool fn_eval_eql(Scope *a, Scope *b) {
55935653}
55945654
55955655// Deprecated. Use type_has_bits2.
5596bool type_has_bits(ZigType *type_entry) {
5597 assert(type_entry != nullptr);
5598 assert(!type_is_invalid(type_entry));
5599 assert(type_is_resolved(type_entry, ResolveStatusZeroBitsKnown));
5600 return type_entry->abi_size != 0;
5656bool type_has_bits(CodeGen *g, ZigType *type_entry) {
5657 Error err;
5658 bool result;
5659 if ((err = type_has_bits2(g, type_entry, &result))) {
5660 codegen_report_errors_and_exit(g);
5661 }
5662 return result;
56015663}
56025664
56035665// Whether the type has bits at runtime.
......@@ -5687,7 +5749,7 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
56875749 case ZigTypeIdEnum:
56885750 case ZigTypeIdInt:
56895751 case ZigTypeIdVector:
5690 return type_has_bits(type_entry) ? OnePossibleValueNo : OnePossibleValueYes;
5752 return type_has_bits(g, type_entry) ? OnePossibleValueNo : OnePossibleValueYes;
56915753 case ZigTypeIdPointer: {
56925754 ZigType *elem_type = type_entry->data.pointer.child_type;
56935755 // 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) {
63656427 }
63666428 if (await->base.base.ref_count == 0)
63676429 continue;
6368 if (!type_has_bits(await->base.value->type))
6430 if (!type_has_bits(g, await->base.value->type))
63696431 continue;
63706432 await->result_loc = ir_create_alloca(g, await->base.base.scope, await->base.base.source_node, fn,
63716433 await->base.value->type, "");
......@@ -6406,7 +6468,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
64066468 continue;
64076469 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))
64086470 return ErrorSemanticAnalyzeFail;
6409 if (!type_has_bits(instruction->value->type))
6471 if (!type_has_bits(g, instruction->value->type))
64106472 continue;
64116473 if (scope_needs_spill(instruction->base.scope)) {
64126474 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) {
64656527 ZigType *ptr_type = instruction->base.value->type;
64666528 assert(ptr_type->id == ZigTypeIdPointer);
64676529 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))
64696531 continue;
64706532 if (instruction->base.base.ref_count == 0)
64716533 continue;
......@@ -6763,7 +6825,7 @@ bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b) {
67636825 if (bigint_cmp(&union1->tag, &union2->tag) == CmpEQ) {
67646826 TypeUnionField *field = find_union_field_by_tag(a->type, &union1->tag);
67656827 assert(field != nullptr);
6766 if (!type_has_bits(field->type_entry))
6828 if (!type_has_bits(g, field->type_entry))
67676829 return true;
67686830 assert(find_union_field_by_tag(a->type, &union2->tag) != nullptr);
67696831 return const_values_equal(g, union1->payload, union2->payload);
......@@ -6826,7 +6888,7 @@ bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b) {
68266888 case ZigTypeIdNull:
68276889 zig_panic("TODO");
68286890 case ZigTypeIdOptional:
6829 if (get_codegen_ptr_type(a->type) != nullptr)
6891 if (get_src_ptr_type(a->type) != nullptr)
68306892 return const_values_equal_ptr(a, b);
68316893 if (a->data.x_optional == nullptr || b->data.x_optional == nullptr) {
68326894 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) {
70977159 }
70987160 case ZigTypeIdOptional:
70997161 {
7100 if (get_codegen_ptr_type(const_val->type) != nullptr)
7162 if (get_src_ptr_type(const_val->type) != nullptr)
71017163 return render_const_val_ptr(g, buf, const_val, type_entry->data.maybe.child_type);
71027164 if (type_entry->data.maybe.child_type->id == ZigTypeIdErrorSet)
71037165 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
78817943}
78827944
78837945X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) {
7946 Error err;
7947
78847948 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)
78867952 return X64CABIClass_INTEGER;
78877953
78887954 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) {
78987964}
78997965
79007966// NOTE this does not depend on x86_64
7901bool type_is_c_abi_int(CodeGen *g, ZigType *ty) {
7902 return (ty->id == ZigTypeIdInt ||
7967Error type_is_c_abi_int(CodeGen *g, ZigType *ty, bool *result) {
7968 if (ty->id == ZigTypeIdInt ||
79037969 ty->id == ZigTypeIdFloat ||
79047970 ty->id == ZigTypeIdBool ||
79057971 ty->id == ZigTypeIdEnum ||
79067972 ty->id == ZigTypeIdVoid ||
7907 ty->id == ZigTypeIdUnreachable ||
7908 get_codegen_ptr_type(ty) != nullptr);
7973 ty->id == ZigTypeIdUnreachable)
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;
79097993}
79107994
79117995uint32_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
80368120 if (ResolveStatusLLVMFwdDecl >= wanted_resolve_status) return;
80378121 }
80388122
8039 if (!type_has_bits(child_type)) {
8123 if (!type_has_bits(g, child_type)) {
80408124 LLVMTypeRef element_types[] = {
80418125 usize_llvm_type,
80428126 };
......@@ -8145,7 +8229,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
81458229 }
81468230
81478231 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) ?
81498233 LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&struct_type->name)) : LLVMVoidType();
81508234 unsigned dwarf_kind = ZigLLVMTag_DW_structure_type();
81518235 struct_type->llvm_di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,
......@@ -8175,7 +8259,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
81758259 for (size_t i = 0; i < field_count; i += 1) {
81768260 TypeStructField *field = struct_type->data.structure.fields[i];
81778261 ZigType *field_type = field->type_entry;
8178 if (!type_has_bits(field_type))
8262 if (!type_has_bits(g, field_type))
81798263 continue;
81808264 (void)get_llvm_type(g, field_type);
81818265 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
81898273 for (size_t i = 0; i < field_count; i += 1) {
81908274 TypeStructField *field = struct_type->data.structure.fields[i];
81918275 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))
81938277 continue;
81948278 LLVMTypeRef field_llvm_type = get_llvm_type(g, field_type);
81958279 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
82008284 TypeStructField *field = struct_type->data.structure.fields[i];
82018285 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)) {
82048288 field->gen_index = SIZE_MAX;
82058289 continue;
82068290 }
......@@ -8247,7 +8331,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
82478331 // find the next non-zero-byte field for offset calculations
82488332 size_t next_src_field_index = i + 1;
82498333 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))
82518335 break;
82528336 }
82538337 size_t next_abi_align;
......@@ -8293,7 +8377,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
82938377 gen_field_index += 1;
82948378 }
82958379
8296 if (type_has_bits(struct_type)) {
8380 if (type_has_bits(g, struct_type)) {
82978381 assert(struct_type->data.structure.gen_field_count == gen_field_index);
82988382 LLVMStructSetBody(struct_type->llvm_type, element_types,
82998383 (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
84058489 ZigType *import = get_scope_import(scope);
84068490 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)) {
84098493 enum_type->llvm_type = g->builtin_types.entry_void->llvm_type;
84108494 enum_type->llvm_di_type = make_empty_namespace_llvm_di_type(g, import, buf_ptr(&enum_type->name),
84118495 decl_node);
......@@ -8487,7 +8571,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
84878571 uint32_t field_count = union_type->data.unionation.src_field_count;
84888572 for (uint32_t i = 0; i < field_count; i += 1) {
84898573 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))
84918575 continue;
84928576
84938577 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
85068590
85078591 }
85088592
8509 if (tag_type == nullptr || !type_has_bits(tag_type)) {
8593 if (tag_type == nullptr || !type_has_bits(g, tag_type)) {
85108594 assert(most_aligned_union_member != nullptr);
85118595
85128596 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
86168700 if (resolve_pointer_zero_bits(g, type) != ErrorNone)
86178701 zig_unreachable();
86188702
8619 if (!type_has_bits(type)) {
8703 if (!type_has_bits(g, type)) {
86208704 type->llvm_type = g->builtin_types.entry_void->llvm_type;
86218705 type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;
86228706 return;
......@@ -8669,7 +8753,7 @@ static void resolve_llvm_types_pointer(CodeGen *g, ZigType *type, ResolveStatus
86698753static void resolve_llvm_types_integer(CodeGen *g, ZigType *type) {
86708754 if (type->llvm_di_type != nullptr) return;
86718755
8672 if (!type_has_bits(type)) {
8756 if (!type_has_bits(g, type)) {
86738757 type->llvm_type = g->builtin_types.entry_void->llvm_type;
86748758 type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;
86758759 return;
......@@ -8705,14 +8789,14 @@ static void resolve_llvm_types_optional(CodeGen *g, ZigType *type, ResolveStatus
87058789 ZigLLVMDIType *bool_llvm_di_type = get_llvm_di_type(g, g->builtin_types.entry_bool);
87068790
87078791 ZigType *child_type = type->data.maybe.child_type;
8708 if (!type_has_bits(child_type)) {
8792 if (!type_has_bits(g, child_type)) {
87098793 type->llvm_type = bool_llvm_type;
87108794 type->llvm_di_type = bool_llvm_di_type;
87118795 type->data.maybe.resolve_status = ResolveStatusLLVMFull;
87128796 return;
87138797 }
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) {
87168800 type->llvm_type = get_llvm_type(g, child_type);
87178801 type->llvm_di_type = get_llvm_di_type(g, child_type);
87188802 type->data.maybe.resolve_status = ResolveStatusLLVMFull;
......@@ -8778,11 +8862,11 @@ static void resolve_llvm_types_error_union(CodeGen *g, ZigType *type) {
87788862 ZigType *payload_type = type->data.error_union.payload_type;
87798863 ZigType *err_set_type = type->data.error_union.err_set_type;
87808864
8781 if (!type_has_bits(payload_type)) {
8782 assert(type_has_bits(err_set_type));
8865 if (!type_has_bits(g, payload_type)) {
8866 assert(type_has_bits(g, err_set_type));
87838867 type->llvm_type = get_llvm_type(g, err_set_type);
87848868 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)) {
87868870 type->llvm_type = get_llvm_type(g, payload_type);
87878871 type->llvm_di_type = get_llvm_di_type(g, payload_type);
87888872 } else {
......@@ -8852,7 +8936,7 @@ static void resolve_llvm_types_error_union(CodeGen *g, ZigType *type) {
88528936static void resolve_llvm_types_array(CodeGen *g, ZigType *type) {
88538937 if (type->llvm_di_type != nullptr) return;
88548938
8855 if (!type_has_bits(type)) {
8939 if (!type_has_bits(g, type)) {
88568940 type->llvm_type = g->builtin_types.entry_void->llvm_type;
88578941 type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;
88588942 return;
......@@ -8893,7 +8977,7 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {
88938977 if (is_async) {
88948978 gen_return_type = g->builtin_types.entry_void;
88958979 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)) {
88978981 gen_return_type = g->builtin_types.entry_void;
88988982 param_di_types.append(nullptr);
88998983 } else if (first_arg_return) {
......@@ -8940,11 +9024,11 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {
89409024 gen_param_info->src_index = i;
89419025 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))
89449028 continue;
89459029
89469030 ZigType *gen_type;
8947 if (handle_is_ptr(type_entry)) {
9031 if (handle_is_ptr(g, type_entry)) {
89489032 gen_type = get_pointer_to_type(g, type_entry, true);
89499033 gen_param_info->is_byval = true;
89509034 } else {
......@@ -9098,7 +9182,7 @@ static void resolve_llvm_types_any_frame(CodeGen *g, ZigType *any_frame_type, Re
90989182 field_types.append(usize_type_ref); // resume_index
90999183 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);
91029186 if (have_result_type) {
91039187 field_types.append(get_llvm_type(g, ptr_result_type)); // result_ptr_callee
91049188 field_types.append(get_llvm_type(g, ptr_result_type)); // result_ptr_awaiter
......@@ -9379,7 +9463,7 @@ bool is_opt_err_set(ZigType *ty) {
93799463bool type_has_optional_repr(ZigType *ty) {
93809464 if (ty->id != ZigTypeIdOptional) {
93819465 return false;
9382 } else if (get_codegen_ptr_type(ty) != nullptr) {
9466 } else if (get_src_ptr_type(ty) != nullptr) {
93839467 return false;
93849468 } else if (is_opt_err_set(ty)) {
93859469 return false;
......@@ -9471,6 +9555,58 @@ bool type_is_numeric(ZigType *ty) {
94719555 zig_unreachable();
94729556}
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
94749610static void dump_value_indent(ZigValue *val, int indent) {
94759611 for (int i = 0; i < indent; i += 1) {
94769612 fprintf(stderr, " ");
......@@ -9548,15 +9684,20 @@ static void dump_value_indent(ZigValue *val, int indent) {
95489684 return;
95499685
95509686 case ZigTypeIdOptional:
9551 fprintf(stderr, "<\n");
9552 dump_value_indent(val->data.x_optional, indent + 1);
9687 if (get_src_ptr_type(val->type) != nullptr) {
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) {
9555 fprintf(stderr, " ");
9695 for (int i = 0; i < indent; i += 1) {
9696 fprintf(stderr, " ");
9697 }
9698 fprintf(stderr, ">\n");
9699 return;
95569700 }
9557 fprintf(stderr, ">\n");
9558 return;
9559
95609701 case ZigTypeIdErrorUnion:
95619702 if (val->data.x_err_union.payload != nullptr) {
95629703 fprintf(stderr, "<\n");
......@@ -9572,52 +9713,14 @@ static void dump_value_indent(ZigValue *val, int indent) {
95729713 return;
95739714
95749715 case ZigTypeIdPointer:
9575 switch (val->data.x_ptr.special) {
9576 case ConstPtrSpecialInvalid:
9577 fprintf(stderr, "<!invalid ptr!>\n");
9578 return;
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;
9716 return dump_value_indent_ptr(val, indent);
9717
9718 case ZigTypeIdErrorSet:
9719 return dump_value_indent_error_set(val, indent);
96169720
96179721 case ZigTypeIdVector:
96189722 case ZigTypeIdArray:
96199723 case ZigTypeIdNull:
9620 case ZigTypeIdErrorSet:
96219724 case ZigTypeIdEnum:
96229725 case ZigTypeIdUnion:
96239726 case ZigTypeIdFn:
src/analyze.hpp+12-6
......@@ -44,14 +44,20 @@ ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry);
4444ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *full_name, Buf *bare_name);
4545ZigType *get_test_fn_type(CodeGen *g);
4646ZigType *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);
5050Error type_has_bits2(CodeGen *g, ZigType *type_entry, bool *result);
5151
5252Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result);
5353bool 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
5662enum SourceKind {
5763 SourceKindRoot,
......@@ -68,7 +74,6 @@ Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name);
6874void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node, bool allow_lazy);
6975
7076ZigType *get_src_ptr_type(ZigType *type);
71ZigType *get_codegen_ptr_type(ZigType *type);
7277uint32_t get_ptr_align(CodeGen *g, ZigType *type);
7378bool get_ptr_const(ZigType *type);
7479ZigType *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);
8792bool is_ref(ZigType *type_entry);
8893bool is_array_ref(ZigType *type_entry);
8994bool 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);
9196void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node);
9297ZigFn *scope_fn_entry(Scope *scope);
9398ZigPackage *scope_package(Scope *scope);
......@@ -223,7 +228,8 @@ Error ATTRIBUTE_MUST_USE file_fetch(CodeGen *g, Buf *resolved_path, Buf *content
223228
224229void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk);
225230X64CABIClass 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);
227233bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id);
228234const char *container_string(ContainerKind kind);
229235
src/codegen.cpp+98-98
......@@ -313,7 +313,7 @@ struct CalcLLVMFieldIndex {
313313};
314314
315315static 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;
317317 uint32_t ty_align = get_abi_alignment(g, ty);
318318 if (calc->offset % ty_align != 0) {
319319 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
334334 calc_llvm_field_index_add(g, calc, g->builtin_types.entry_usize); // resume index
335335 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)) {
338338 calc_llvm_field_index_add(g, calc, g->builtin_types.entry_usize); // *ReturnType (callee's)
339339 calc_llvm_field_index_add(g, calc, g->builtin_types.entry_usize); // *ReturnType (awaiter's)
340340 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) {
383383 return UINT32_MAX;
384384 }
385385 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);
387387 return first_arg_ret ? 1 : 0;
388388}
389389
......@@ -581,9 +581,9 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
581581 addLLVMArgAttr(llvm_fn, 0, "nonnull");
582582 } else {
583583 unsigned init_gen_i = 0;
584 if (!type_has_bits(return_type)) {
584 if (!type_has_bits(g, return_type)) {
585585 // nothing to do
586 } else if (type_is_nonnull_ptr(return_type)) {
586 } else if (type_is_nonnull_ptr(g, return_type)) {
587587 addLLVMAttr(llvm_fn, 0, "nonnull");
588588 } else if (want_first_arg_sret(g, &fn_type->data.fn.fn_type_id)) {
589589 // Sret pointers must not be address 0
......@@ -859,8 +859,8 @@ static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, co
859859}
860860
861861static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type, ZigType *ptr_type) {
862 if (type_has_bits(type)) {
863 if (handle_is_ptr(type)) {
862 if (type_has_bits(g, type)) {
863 if (handle_is_ptr(g, type)) {
864864 return ptr;
865865 } else {
866866 assert(ptr_type->id == ZigTypeIdPointer);
......@@ -1671,10 +1671,10 @@ static void gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type,
16711671 assert(ptr_type->id == ZigTypeIdPointer);
16721672 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))
16751675 return;
16761676
1677 if (handle_is_ptr(child_type)) {
1677 if (handle_is_ptr(g, child_type)) {
16781678 assert(LLVMGetTypeKind(LLVMTypeOf(value)) == LLVMPointerTypeKind);
16791679 assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
16801680
......@@ -1782,7 +1782,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstGen *instruction) {
17821782 render_const_val(g, instruction->value, "");
17831783 // we might have to do some pointer casting here due to the way union
17841784 // 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)) {
17861786 render_const_val_global(g, instruction->value, "");
17871787 ZigType *ptr_type = get_pointer_to_type(g, instruction->value->type, true);
17881788 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_
18791879 break;
18801880 }
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 ||
18831883 ty->id == ZigTypeIdInt // TODO investigate if we need to change this
18841884 ) {
18851885 switch (fn_walk->id) {
18861886 case FnWalkIdAttrs: {
1887 ZigType *ptr_type = get_codegen_ptr_type(ty);
1887 ZigType *ptr_type = get_codegen_ptr_type_bail(g, ty);
18881888 if (ptr_type != nullptr) {
1889 if (type_is_nonnull_ptr(ty)) {
1889 if (type_is_nonnull_ptr(g, ty)) {
18901890 addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull");
18911891 }
18921892 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_
19281928 {
19291929 // Arrays are just pointers
19301930 if (ty->id == ZigTypeIdArray) {
1931 assert(handle_is_ptr(ty));
1931 assert(handle_is_ptr(g, ty));
19321932 switch (fn_walk->id) {
19331933 case FnWalkIdAttrs:
19341934 // 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_
19651965 X64CABIClass abi_class = type_c_abi_x86_64_class(g, ty);
19661966 size_t ty_size = type_size(g, ty);
19671967 if (abi_class == X64CABIClass_MEMORY || abi_class == X64CABIClass_MEMORY_nobyval) {
1968 assert(handle_is_ptr(ty));
1968 assert(handle_is_ptr(g, ty));
19691969 switch (fn_walk->id) {
19701970 case FnWalkIdAttrs:
19711971 if (abi_class != X64CABIClass_MEMORY_nobyval) {
......@@ -2088,7 +2088,7 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
20882088 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {
20892089 IrInstGen *param_instruction = instruction->args[call_i];
20902090 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)) {
20922092 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);
20932093 assert(param_value);
20942094 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) {
21192119 if ((param_type->id == ZigTypeIdPointer && param_type->data.pointer.is_const) || is_byval) {
21202120 addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "readonly");
21212121 }
2122 if (get_codegen_ptr_type(param_type) != nullptr) {
2122 if (get_codegen_ptr_type_bail(g, param_type) != nullptr) {
21232123 addLLVMArgAttrInt(llvm_fn, (unsigned)gen_index, "align", get_ptr_align(g, param_type));
21242124 }
2125 if (type_is_nonnull_ptr(param_type)) {
2125 if (type_is_nonnull_ptr(g, param_type)) {
21262126 addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "nonnull");
21272127 }
21282128 break;
......@@ -2137,7 +2137,7 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
21372137 assert(variable);
21382138 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)) {
21412141 clear_debug_source_node(g);
21422142 ZigType *fn_type = fn_table_entry->type_entry;
21432143 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) {
24042404 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
24052405
24062406 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);
24082408 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
24112411 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);
24132413 if (need_store) {
24142414 // It didn't get written to the result ptr. We do that now.
24152415 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
25122512 gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);
25132513 LLVMBuildRetVoid(g->builder);
25142514 } 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))
25162516 {
25172517 if (instruction->operand == nullptr) {
25182518 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,
28832883 } else if (scalar_type->id == ZigTypeIdEnum ||
28842884 scalar_type->id == ZigTypeIdErrorSet ||
28852885 scalar_type->id == ZigTypeIdBool ||
2886 get_codegen_ptr_type(scalar_type) != nullptr)
2886 get_codegen_ptr_type_bail(g, scalar_type) != nullptr)
28872887 {
28882888 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);
28892889 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
31493149 ZigType *array_type = actual_type->data.pointer.child_type;
31503150 assert(array_type->id == ZigTypeIdArray);
31513151
3152 if (type_has_bits(actual_type)) {
3152 if (type_has_bits(g, actual_type)) {
31533153 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, result_loc, ptr_index, "");
31543154 LLVMValueRef indices[] = {
31553155 LLVMConstNull(g->builtin_types.entry_usize->llvm_type),
......@@ -3175,7 +3175,7 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutableGen *executable,
31753175 IrInstGenPtrCast *instruction)
31763176{
31773177 ZigType *wanted_type = instruction->base.value->type;
3178 if (!type_has_bits(wanted_type)) {
3178 if (!type_has_bits(g, wanted_type)) {
31793179 return nullptr;
31803180 }
31813181 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
......@@ -3204,8 +3204,8 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutableGen *executable,
32043204 ZigType *actual_type = instruction->operand->value->type;
32053205 LLVMValueRef value = ir_llvm_value(g, instruction->operand);
32063206
3207 bool wanted_is_ptr = handle_is_ptr(wanted_type);
3208 bool actual_is_ptr = handle_is_ptr(actual_type);
3207 bool wanted_is_ptr = handle_is_ptr(g, wanted_type);
3208 bool actual_is_ptr = handle_is_ptr(g, actual_type);
32093209 if (wanted_is_ptr == actual_is_ptr) {
32103210 // We either bitcast the value directly or bitcast the pointer which does a pointer cast
32113211 LLVMTypeRef wanted_type_ref = wanted_is_ptr ?
......@@ -3352,9 +3352,9 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutableGen *executable
33523352 g->err_tag_type, wanted_type, target_val);
33533353 } else if (actual_type->id == ZigTypeIdErrorUnion) {
33543354 // 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)) {
33583358 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
33593359 g->err_tag_type, wanted_type, target_val);
33603360 } else {
......@@ -3442,7 +3442,7 @@ static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutableGen *executable,
34423442}
34433443
34443444static 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))
34463446 return;
34473447
34483448 var->value_ref = ir_llvm_value(g, var->ptr_instruction);
......@@ -3460,7 +3460,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutableGen *executable,
34603460 IrInstGenLoadPtr *instruction)
34613461{
34623462 ZigType *child_type = instruction->base.value->type;
3463 if (!type_has_bits(child_type))
3463 if (!type_has_bits(g, child_type))
34643464 return nullptr;
34653465
34663466 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
......@@ -3495,7 +3495,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutableGen *executable,
34953495 LLVMValueRef shift_amt_val = LLVMConstInt(LLVMTypeOf(containing_int), shift_amt, false);
34963496 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)) {
34993499 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
35003500 LLVMTypeRef same_size_int = LLVMIntType(size_in_bits);
35013501 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
36423642}
36433643
36443644static 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));
36463646 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, get_llvm_type(g, value_type));
36473647 assert(size_bytes > 0);
36483648 assert(ptr_align_bytes > 0);
......@@ -3708,7 +3708,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutableGen *executable, I
37083708 if (instruction->base.value->special != ConstValSpecialRuntime)
37093709 return ir_llvm_value(g, &instruction->base);
37103710 ZigVar *var = instruction->var;
3711 if (type_has_bits(var->var_type)) {
3711 if (type_has_bits(g, var->var_type)) {
37123712 assert(var->value_ref);
37133713 return var->value_ref;
37143714 } else {
......@@ -3719,7 +3719,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutableGen *executable, I
37193719static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutableGen *executable,
37203720 IrInstGenReturnPtr *instruction)
37213721{
3722 if (!type_has_bits(instruction->base.value->type))
3722 if (!type_has_bits(g, instruction->base.value->type))
37233723 return nullptr;
37243724 ir_assert(g->cur_ret_ptr != nullptr, &instruction->base);
37253725 return g->cur_ret_ptr;
......@@ -3733,7 +3733,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutableGen *executable,
37333733 LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index);
37343734 assert(subscript_value);
37353735
3736 if (!type_has_bits(array_type))
3736 if (!type_has_bits(g, array_type))
37373737 return nullptr;
37383738
37393739 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,
37933793 assert(array_type->data.structure.special == StructSpecialSlice);
37943794
37953795 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)) {
37973797 if (safety_check_on) {
37983798 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMIntegerTypeKind);
37993799 add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, array_ptr);
......@@ -3872,7 +3872,7 @@ static void render_async_spills(CodeGen *g) {
38723872 for (size_t var_i = 0; var_i < g->cur_fn->variable_list.length; var_i += 1) {
38733873 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)) {
38763876 continue;
38773877 }
38783878 if (ir_get_var_is_comptime(var))
......@@ -3992,7 +3992,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
39923992 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
39933993
39943994 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
39973997 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
43124312 gen_assert_resume_id(g, &instruction->base, ResumeIdReturn, PanicMsgIdResumedAnAwaitingFn, nullptr);
43134313 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))
43164316 return nullptr;
43174317
43184318 if (result_loc != nullptr) {
......@@ -4372,7 +4372,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
43724372 } else if (first_arg_ret) {
43734373 set_call_instr_sret(g, result);
43744374 return result_loc;
4375 } else if (handle_is_ptr(src_return_type)) {
4375 } else if (handle_is_ptr(g, src_return_type)) {
43764376 LLVMValueRef store_instr = LLVMBuildStore(g->builder, result, result_loc);
43774377 LLVMSetAlignment(store_instr, get_ptr_align(g, instruction->result_loc->value->type));
43784378 return result_loc;
......@@ -4397,7 +4397,7 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutableGen *exec
43974397 ZigType *struct_ptr_type = instruction->struct_ptr->value->type;
43984398 TypeStructField *field = instruction->field;
43994399
4400 if (!type_has_bits(field->type_entry))
4400 if (!type_has_bits(g, field->type_entry))
44014401 return nullptr;
44024402
44034403 if (struct_ptr_type->id == ZigTypeIdPointer &&
......@@ -4448,9 +4448,9 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutableGen *execu
44484448
44494449 TypeUnionField *field = instruction->field;
44504450
4451 if (!type_has_bits(field->type_entry)) {
4451 if (!type_has_bits(g, field->type_entry)) {
44524452 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))
44544454 return nullptr;
44554455
44564456 // 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
46724672 (maybe_type->id == ZigTypeIdPointer && maybe_type->data.pointer.allow_zero));
46734673
46744674 ZigType *child_type = maybe_type->data.maybe.child_type;
4675 if (!type_has_bits(child_type))
4675 if (!type_has_bits(g, child_type))
46764676 return maybe_handle;
46774677
4678 bool is_scalar = !handle_is_ptr(maybe_type);
4678 bool is_scalar = !handle_is_ptr(g, maybe_type);
46794679 if (is_scalar)
46804680 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
47134713
47144714 LLVMPositionBuilderAtEnd(g->builder, ok_block);
47154715 }
4716 if (!type_has_bits(child_type)) {
4716 if (!type_has_bits(g, child_type)) {
47174717 if (instruction->initializing) {
47184718 LLVMValueRef non_null_bit = LLVMConstInt(LLVMInt1Type(), 1, false);
47194719 gen_store_untyped(g, non_null_bit, base_ptr, 0, false);
47204720 }
47214721 return nullptr;
47224722 } else {
4723 bool is_scalar = !handle_is_ptr(maybe_type);
4723 bool is_scalar = !handle_is_ptr(g, maybe_type);
47244724 if (is_scalar) {
47254725 return base_ptr;
47264726 } else {
......@@ -4899,11 +4899,11 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutableGen *executable,
48994899}
49004900
49014901static 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))
49034903 return nullptr;
49044904
49054905 LLVMTypeRef phi_type;
4906 if (handle_is_ptr(instruction->base.value->type)) {
4906 if (handle_is_ptr(g, instruction->base.value->type)) {
49074907 phi_type = LLVMPointerType(get_llvm_type(g,instruction->base.value->type), 0);
49084908 } else {
49094909 phi_type = get_llvm_type(g, instruction->base.value->type);
......@@ -4921,7 +4921,7 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrIns
49214921}
49224922
49234923static 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)) {
49254925 return nullptr;
49264926 }
49274927 if (instruction->operand->id == IrInstGenIdCall) {
......@@ -4931,7 +4931,7 @@ static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutableGen *executable, IrIns
49314931 }
49324932 }
49334933 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)) {
49354935 return value;
49364936 } else {
49374937 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
......@@ -5232,20 +5232,20 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutableGen *executable, I
52325232 assert(optional_type->id == ZigTypeIdOptional);
52335233 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)) {
52365236 LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, "");
52375237 LLVMValueRef success_bit = LLVMBuildExtractValue(g->builder, result_val, 1, "");
52385238 return LLVMBuildSelect(g->builder, success_bit, LLVMConstNull(get_llvm_type(g, child_type)), payload_val, "");
52395239 }
52405240
52415241 // 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)) {
52435243 return nullptr;
52445244 }
52455245
52465246 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
52475247 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
52505250 LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, "");
52515251 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
53735373 }
53745374 }
53755375 }
5376 if (!type_has_bits(array_type)) {
5376 if (!type_has_bits(g, array_type)) {
53775377 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, slice_len_index, "");
53785378
53795379 // 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
54095409 }
54105410 }
54115411
5412 if (type_has_bits(array_type)) {
5412 if (type_has_bits(g, array_type)) {
54135413 size_t gen_ptr_index = instruction->base.value->type->data.structure.fields[slice_ptr_index]->gen_index;
54145414 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, "");
54155415 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,
55975597 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union);
55985598
55995599 LLVMValueRef err_val;
5600 if (type_has_bits(payload_type)) {
5600 if (type_has_bits(g, payload_type)) {
56015601 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, err_union_handle, err_union_err_index, "");
56025602 err_val = gen_load_untyped(g, err_val_ptr, 0, false, "");
56035603 } else {
......@@ -5619,7 +5619,7 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutableGen *execu
56195619 ZigType *err_union_type = ptr_type->data.pointer.child_type;
56205620 ZigType *payload_type = err_union_type->data.error_union.payload_type;
56215621 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)) {
56235623 return err_union_ptr;
56245624 } else {
56255625 // TODO assign undef to the payload
......@@ -5659,13 +5659,13 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutableGen *ex
56595659
56605660 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)) {
56635663 return err_union_handle;
56645664 }
56655665
56665666 if (want_safety) {
56675667 LLVMValueRef err_val;
5668 if (type_has_bits(payload_type)) {
5668 if (type_has_bits(g, payload_type)) {
56695669 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, err_union_handle, err_union_err_index, "");
56705670 err_val = gen_load_untyped(g, err_val_ptr, 0, false, "");
56715671 } else {
......@@ -5682,7 +5682,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutableGen *ex
56825682 LLVMPositionBuilderAtEnd(g->builder, ok_block);
56835683 }
56845684
5685 if (type_has_bits(payload_type)) {
5685 if (type_has_bits(g, payload_type)) {
56865686 if (instruction->initializing) {
56875687 LLVMValueRef err_tag_ptr = LLVMBuildStructGEP(g->builder, err_union_handle, err_union_err_index, "");
56885688 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
57045704
57055705 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)) {
57085708 LLVMValueRef result = LLVMConstAllOnes(LLVMInt1Type());
57095709 if (instruction->result_loc != nullptr) {
57105710 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
......@@ -5714,7 +5714,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutableGen *executa
57145714 }
57155715
57165716 LLVMValueRef payload_val = ir_llvm_value(g, instruction->operand);
5717 if (!handle_is_ptr(wanted_type)) {
5717 if (!handle_is_ptr(g, wanted_type)) {
57185718 if (instruction->result_loc != nullptr) {
57195719 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
57205720 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
57405740
57415741 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))
57445744 return err_val;
57455745
57465746 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
57615761 ZigType *payload_type = wanted_type->data.error_union.payload_type;
57625762 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)) {
57655765 return ir_llvm_value(g, instruction->operand);
57665766 }
57675767
57685768 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))
57715771 return ok_err_val;
57725772
57735773
......@@ -5788,7 +5788,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutableGen *executable,
57885788 ZigType *union_type = instruction->value->value->type;
57895789
57905790 ZigType *tag_type = union_type->data.unionation.tag_type;
5791 if (!type_has_bits(tag_type))
5791 if (!type_has_bits(g, tag_type))
57925792 return nullptr;
57935793
57945794 LLVMValueRef union_val = ir_llvm_value(g, instruction->value);
......@@ -5825,7 +5825,7 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutableGen *executable
58255825 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
58265826 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) {
58295829 return ZigLLVMBuildAtomicRMW(g->builder, op, ptr, operand, ordering, g->is_single_threaded);
58305830 }
58315831
......@@ -5927,7 +5927,7 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutableGen *execu
59275927{
59285928 ZigType *array_type = instruction->base.value->type;
59295929 assert(array_type->id == ZigTypeIdArray);
5930 assert(handle_is_ptr(array_type));
5930 assert(handle_is_ptr(g, array_type));
59315931 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
59325932 LLVMValueRef vector = ir_llvm_value(g, instruction->vector);
59335933
......@@ -5961,7 +5961,7 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutableGen *execu
59615961{
59625962 ZigType *vector_type = instruction->base.value->type;
59635963 assert(vector_type->id == ZigTypeIdVector);
5964 assert(!handle_is_ptr(vector_type));
5964 assert(!handle_is_ptr(g, vector_type));
59655965 LLVMValueRef array_ptr = ir_llvm_value(g, instruction->array);
59665966 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,
60576057{
60586058 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
60596059 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)) {
60616061 LLVMValueRef their_result_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, frame_ret_start, "");
60626062 their_result_ptr = LLVMBuildLoad(g->builder, their_result_ptr_ptr, "");
60636063 if (result_loc != nullptr) {
......@@ -6082,7 +6082,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
60826082 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
60836083 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
60846084 }
6085 if (non_async && type_has_bits(result_type)) {
6085 if (non_async && type_has_bits(g, result_type)) {
60866086 LLVMValueRef result_ptr = (result_loc == nullptr) ? their_result_ptr : result_loc;
60876087 return get_handle_value(g, result_ptr, result_type, ptr_result_type);
60886088 } else {
......@@ -6115,7 +6115,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutableGen *executable, IrI
61156115 // This code is as if it is running inside the suspend block.
61166116
61176117 // supply the awaiter return pointer
6118 if (type_has_bits(result_type)) {
6118 if (type_has_bits(g, result_type)) {
61196119 LLVMValueRef awaiter_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, frame_ret_start + 1, "");
61206120 if (result_loc == nullptr) {
61216121 // no copy needed
......@@ -6599,7 +6599,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Zig
65996599 }
66006600
66016601 ZigType *type_entry = const_val->type;
6602 assert(type_has_bits(type_entry));
6602 assert(type_has_bits(g, type_entry));
66036603 switch (type_entry->id) {
66046604 case ZigTypeIdInvalid:
66056605 case ZigTypeIdMetaType:
......@@ -6732,7 +6732,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha
67326732 {
67336733 ZigValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;
67346734 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)) {
67366736 if (array_const_val->type->data.array.sentinel != nullptr) {
67376737 ZigValue *pointee = array_const_val->type->data.array.sentinel;
67386738 render_const_val(g, pointee, "");
......@@ -6758,7 +6758,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha
67586758 {
67596759 ZigValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;
67606760 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)) {
67626762 // make this a null pointer
67636763 ZigType *usize = g->builtin_types.entry_usize;
67646764 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
67776777 {
67786778 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_code.err_union_val;
67796779 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)) {
67816781 // make this a null pointer
67826782 ZigType *usize = g->builtin_types.entry_usize;
67836783 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
67936793 {
67946794 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_payload.err_union_val;
67956795 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)) {
67976797 // make this a null pointer
67986798 ZigType *usize = g->builtin_types.entry_usize;
67996799 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
68096809 {
68106810 ZigValue *optional_const_val = const_val->data.x_ptr.data.base_optional_payload.optional_val;
68116811 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)) {
68136813 // make this a null pointer
68146814 ZigType *usize = g->builtin_types.entry_usize;
68156815 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
68476847 Error err;
68486848
68496849 ZigType *type_entry = const_val->type;
6850 assert(type_has_bits(type_entry));
6850 assert(type_has_bits(g, type_entry));
68516851
68526852check: switch (const_val->special) {
68536853 case ConstValSpecialLazy:
......@@ -6900,12 +6900,12 @@ check: switch (const_val->special) {
69006900 case ZigTypeIdOptional:
69016901 {
69026902 ZigType *child_type = type_entry->data.maybe.child_type;
6903 if (!type_has_bits(child_type)) {
6904 return LLVMConstInt(LLVMInt1Type(), const_val->data.x_optional ? 1 : 0, false);
6905 } else if (get_codegen_ptr_type(type_entry) != nullptr) {
6903 if (get_src_ptr_type(type_entry) != nullptr) {
69066904 return gen_const_val_ptr(g, const_val, name);
69076905 } else if (child_type->id == ZigTypeIdErrorSet) {
69086906 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);
69096909 } else {
69106910 LLVMValueRef child_val;
69116911 LLVMValueRef maybe_val;
......@@ -7128,7 +7128,7 @@ check: switch (const_val->special) {
71287128 LLVMValueRef union_value_ref;
71297129 bool make_unnamed_struct;
71307130 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)) {
71327132 if (type_entry->data.unionation.gen_tag_index == SIZE_MAX)
71337133 return LLVMGetUndef(get_llvm_type(g, type_entry));
71347134
......@@ -7205,13 +7205,13 @@ check: switch (const_val->special) {
72057205 {
72067206 ZigType *payload_type = type_entry->data.error_union.payload_type;
72077207 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
7208 if (!type_has_bits(payload_type)) {
7209 assert(type_has_bits(err_set_type));
7208 if (!type_has_bits(g, payload_type)) {
7209 assert(type_has_bits(g, err_set_type));
72107210 ErrorTableEntry *err_set = const_val->data.x_err_union.error_set->data.x_err_set;
72117211 uint64_t value = (err_set == nullptr) ? 0 : err_set->value;
72127212 return LLVMConstInt(get_llvm_type(g, g->err_tag_type), value, false);
7213 } else if (!type_has_bits(err_set_type)) {
7214 assert(type_has_bits(payload_type));
7213 } else if (!type_has_bits(g, err_set_type)) {
7214 assert(type_has_bits(g, payload_type));
72157215 return gen_const_val(g, const_val->data.x_err_union.payload, "");
72167216 } else {
72177217 LLVMValueRef err_tag_value;
......@@ -7445,7 +7445,7 @@ static void do_code_gen(CodeGen *g) {
74457445 continue;
74467446 }
74477447
7448 if (!type_has_bits(var->var_type))
7448 if (!type_has_bits(g, var->var_type))
74497449 continue;
74507450
74517451 assert(var->decl_node);
......@@ -7544,7 +7544,7 @@ static void do_code_gen(CodeGen *g) {
75447544 } else {
75457545 if (want_sret) {
75467546 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)) {
75487548 g->cur_ret_ptr = build_alloca(g, fn_type_id->return_type, "result", 0);
75497549 // TODO add debug info variable for this
75507550 } else {
......@@ -7609,7 +7609,7 @@ static void do_code_gen(CodeGen *g) {
76097609 ZigType *child_type = ptr_type->data.pointer.child_type;
76107610 if (type_resolve(g, child_type, ResolveStatusSizeKnown))
76117611 zig_unreachable();
7612 if (!type_has_bits(child_type))
7612 if (!type_has_bits(g, child_type))
76137613 continue;
76147614 if (instruction->base.base.ref_count == 0)
76157615 continue;
......@@ -7640,7 +7640,7 @@ static void do_code_gen(CodeGen *g) {
76407640 for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) {
76417641 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)) {
76447644 continue;
76457645 }
76467646 if (ir_get_var_is_comptime(var))
......@@ -7667,7 +7667,7 @@ static void do_code_gen(CodeGen *g) {
76677667 FnGenParamInfo *gen_info = &fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index];
76687668 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)) {
76717671 if (gen_info->is_byval) {
76727672 gen_type = var->var_type;
76737673 } else {
......@@ -7739,7 +7739,7 @@ static void do_code_gen(CodeGen *g) {
77397739 LLVMValueRef resume_index_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, frame_resume_index, "");
77407740 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)) {
77437743 LLVMValueRef cur_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, frame_ret_start, "");
77447744 g->cur_ret_ptr = LLVMBuildLoad(g->builder, cur_ret_ptr_ptr, "");
77457745 }
......@@ -9847,10 +9847,10 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
98479847 case ZigTypeIdOptional:
98489848 {
98499849 ZigType *child_type = type_entry->data.maybe.child_type;
9850 if (!type_has_bits(child_type)) {
9850 if (!type_has_bits(g, child_type)) {
98519851 buf_init_from_str(out_buf, "bool");
98529852 return;
9853 } else if (type_is_nonnull_ptr(child_type)) {
9853 } else if (type_is_nonnull_ptr(g, child_type)) {
98549854 return get_c_type(g, gen_h, child_type, out_buf);
98559855 } else {
98569856 zig_unreachable();
src/ir.cpp+78-55
......@@ -860,7 +860,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte
860860 if (expected == actual)
861861 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)
864864 return true;
865865
866866 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
1139911399 result.id = ConstCastResultIdInvalid;
1140011400 return result;
1140111401 }
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) &&
1140311403 actual_ptr_type->data.pointer.bit_offset_in_host == wanted_ptr_type->data.pointer.bit_offset_in_host &&
1140411404 actual_ptr_type->data.pointer.host_int_bytes == wanted_ptr_type->data.pointer.host_int_bytes &&
1140511405 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
1253212532static IrInstGen *ir_resolve_cast(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
1253312533 ZigType *wanted_type, CastOp cast_op)
1253412534{
12535 if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {
12535 if (instr_is_comptime(value) || !type_has_bits(ira->codegen, wanted_type)) {
1253612536 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1253712537 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type,
1253812538 result->value, wanted_type))
......@@ -12918,7 +12918,7 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutableGen *exec, AstNo
1291812918 case ConstValSpecialStatic:
1291912919 return ErrorNone;
1292012920 case ConstValSpecialRuntime:
12921 if (!type_has_bits(val->type))
12921 if (!type_has_bits(codegen, val->type))
1292212922 return ErrorNone;
1292312923
1292412924 exec_add_error_node_gen(codegen, exec, source_node,
......@@ -13082,7 +13082,11 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstGen *type_value) {
1308213082}
1308313083
1308413084static 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) {
1308613090 ir_add_error_node(ira, source_node,
1308713091 buf_sprintf("vector element type must be integer, float, bool, or pointer; '%s' is invalid",
1308813092 buf_ptr(&elem_type->name)));
......@@ -13198,7 +13202,7 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
1319813202 return &const_instruction->base;
1319913203 }
1320013204
13201 if (result_loc == nullptr && handle_is_ptr(wanted_type)) {
13205 if (result_loc == nullptr && handle_is_ptr(ira->codegen, wanted_type)) {
1320213206 result_loc = no_result_loc();
1320313207 }
1320413208 IrInstGen *result_loc_inst = nullptr;
......@@ -13246,7 +13250,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins
1324613250 }
1324713251
1324813252 IrInstGen *result_loc_inst;
13249 if (handle_is_ptr(wanted_type)) {
13253 if (handle_is_ptr(ira->codegen, wanted_type)) {
1325013254 if (result_loc == nullptr) result_loc = no_result_loc();
1325113255 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);
1325213256 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,
1335813362 }
1335913363
1336013364 IrInstGen *result_loc_inst;
13361 if (handle_is_ptr(wanted_type)) {
13365 if (handle_is_ptr(ira->codegen, wanted_type)) {
1336213366 if (result_loc == nullptr) result_loc = no_result_loc();
1336313367 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);
1336413368 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,
1338513389
1338613390 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1338713391 result->value->special = ConstValSpecialStatic;
13388 if (get_codegen_ptr_type(wanted_type) != nullptr) {
13392
13393 if (get_src_ptr_type(wanted_type) != nullptr) {
1338913394 result->value->data.x_ptr.special = ConstPtrSpecialNull;
1339013395 } else if (is_opt_err_set(wanted_type)) {
1339113396 result->value->data.x_err_set = nullptr;
......@@ -13434,7 +13439,7 @@ static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInst
1343413439 return ira->codegen->invalid_inst_gen;
1343513440
1343613441 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)) {
1343813443 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), elem_type, nullptr, true, true);
1343913444 } else {
1344013445 result_loc = nullptr;
......@@ -13679,9 +13684,9 @@ static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_ins
1367913684 // If the destination integer type has no bits, then we can emit a comptime
1368013685 // zero. However, we still want to emit a runtime safety check to make sure
1368113686 // the target is zero.
13682 if (!type_has_bits(wanted_type)) {
13687 if (!type_has_bits(ira->codegen, wanted_type)) {
1368313688 assert(wanted_type->id == ZigTypeIdInt);
13684 assert(type_has_bits(target->value->type));
13689 assert(type_has_bits(ira->codegen, target->value->type));
1368513690 ir_build_assert_zero(ira, source_instr, target);
1368613691 IrInstGen *result = ir_const_unsigned(ira, source_instr, 0);
1368713692 result->value->type = wanted_type;
......@@ -15038,7 +15043,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
1503815043 }
1503915044
1504015045 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)) {
1504215047 if (result_loc == nullptr) result_loc = no_result_loc();
1504315048 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true, true);
1504415049 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
1529815303 }
1529915304
1530015305 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))
1530215307 {
1530315308 // result location mechanism took care of it.
1530415309 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) {
1538715392
1538815393static bool optional_value_is_null(ZigValue *val) {
1538915394 assert(val->special == ConstValSpecialStatic);
15390 if (get_codegen_ptr_type(val->type) != nullptr) {
15395 if (get_src_ptr_type(val->type) != nullptr) {
1539115396 if (val->data.x_ptr.special == ConstPtrSpecialNull) {
1539215397 return true;
1539315398 } else if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
......@@ -15406,7 +15411,7 @@ static void set_optional_value_to_null(ZigValue *val) {
1540615411 assert(val->special == ConstValSpecialStatic);
1540715412 if (val->type->id == ZigTypeIdNull) return; // nothing to do
1540815413 assert(val->type->id == ZigTypeIdOptional);
15409 if (get_codegen_ptr_type(val->type) != nullptr) {
15414 if (get_src_ptr_type(val->type) != nullptr) {
1541015415 val->data.x_ptr.special = ConstPtrSpecialNull;
1541115416 } else if (is_opt_err_set(val->type)) {
1541215417 val->data.x_err_set = nullptr;
......@@ -16244,7 +16249,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
1624416249 operator_allowed = false;
1624516250 break;
1624616251 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;
1624816253 break;
1624916254 }
1625016255 if (!operator_allowed) {
......@@ -17894,7 +17899,7 @@ static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
1789417899 if (!exec_has_err_ret_trace(ira->codegen, ira->old_irb.exec)) {
1789517900 IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type);
1789617901 ZigValue *out_val = result->value;
17897 assert(get_codegen_ptr_type(optional_type) != nullptr);
17902 assert(get_src_ptr_type(optional_type) != nullptr);
1789817903 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
1789917904 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;
1790017905 return result;
......@@ -18283,7 +18288,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1828318288 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
1828418289 return ira->codegen->invalid_inst_gen;
1828518290 }
18286 if (!type_has_bits(value_type)) {
18291 if (!type_has_bits(ira->codegen, value_type)) {
1828718292 parent_ptr_align = 0;
1828818293 }
1828918294 // 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
1832818333 if (type_is_invalid(dest_type))
1832918334 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) {
1833218340 ir_add_error(ira, &result_loc->source_instruction->base,
1833318341 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));
1833418342 return ira->codegen->invalid_inst_gen;
......@@ -18340,7 +18348,10 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1834018348 return ira->codegen->invalid_inst_gen;
1834118349 }
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) {
1834418355 ir_add_error(ira, suspend_source_instr,
1834518356 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name)));
1834618357 return ira->codegen->invalid_inst_gen;
......@@ -18400,7 +18411,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1840018411 }
1840118412 }
1840218413 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);
1840418415 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
1840518416 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
1840618417 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,
1911819129 }
1911919130
1912019131 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)) {
1912219133 first_arg = first_arg_ptr;
1912319134 } else {
1912419135 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,
1924719258 }
1924819259
1924919260 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)) {
1925119262 first_arg = first_arg_ptr;
1925219263 } else {
1925319264 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,
1936619377 }
1936719378
1936819379 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)) {
1937019381 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
1937119382 impl_fn_type_id->return_type, nullptr, true, false);
1937219383 if (result_loc != nullptr) {
......@@ -19383,7 +19394,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1938319394 if (res_child_type == ira->codegen->builtin_types.entry_var) {
1938419395 res_child_type = impl_fn_type_id->return_type;
1938519396 }
19386 if (!handle_is_ptr(res_child_type)) {
19397 if (!handle_is_ptr(ira->codegen, res_child_type)) {
1938719398 ir_reset_result(call_result_loc);
1938819399 result_loc = nullptr;
1938919400 }
......@@ -19435,7 +19446,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1943519446
1943619447 IrInstGen *first_arg;
1943719448 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))
1943919450 {
1944019451 first_arg = first_arg_ptr;
1944119452 } else {
......@@ -19504,7 +19515,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1950419515 }
1950519516
1950619517 IrInstGen *result_loc;
19507 if (handle_is_ptr(return_type)) {
19518 if (handle_is_ptr(ira->codegen, return_type)) {
1950819519 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
1950919520 return_type, nullptr, true, false);
1951019521 if (result_loc != nullptr) {
......@@ -19521,7 +19532,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1952119532 if (res_child_type == ira->codegen->builtin_types.entry_var) {
1952219533 res_child_type = return_type;
1952319534 }
19524 if (!handle_is_ptr(res_child_type)) {
19535 if (!handle_is_ptr(ira->codegen, res_child_type)) {
1952519536 ir_reset_result(call_result_loc);
1952619537 result_loc = nullptr;
1952719538 }
......@@ -23346,7 +23357,7 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,
2334623357 return nullptr;
2334723358 }
2334823359
23349 if (!type_has_bits(field->type_entry)) {
23360 if (!type_has_bits(ira->codegen, field->type_entry)) {
2335023361 ir_add_error(ira, &field_name_value->base,
2335123362 buf_sprintf("zero-bit field '%s' in struct '%s' has no offset",
2335223363 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
2426424275 return ErrorSemanticAnalyzeFail;
2426524276 if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown)))
2426624277 return err;
24267 if (!type_has_bits(struct_field->type_entry)) {
24278 if (!type_has_bits(ira->codegen, struct_field->type_entry)) {
2426824279 inner_fields[1]->data.x_optional = nullptr;
2426924280 } else {
2427024281 size_t byte_offset = struct_field->offset;
......@@ -25077,7 +25088,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
2507725088
2507825089 ZigType *result_type = get_optional_type(ira->codegen, operand_type);
2507925090 IrInstGen *result_loc;
25080 if (handle_is_ptr(result_type)) {
25091 if (handle_is_ptr(ira->codegen, result_type)) {
2508125092 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2508225093 result_type, nullptr, true, true);
2508325094 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
2539625407static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr,
2539725408 ZigType *scalar_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)
2539825409{
25410 Error err;
2539925411 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
2540225416 uint32_t len_mask;
2540325417 if (mask->value->type->id == ZigTypeIdVector) {
......@@ -27364,7 +27378,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2736427378 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown)))
2736527379 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) {
2736827382 ErrorMsg *msg = ir_add_error(ira, source_instr,
2736927383 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",
2737027384 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
2742327437
2742427438 // Keep the bigger alignment, it can only help-
2742527439 // 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)) {
2742727441 result = ir_align_cast(ira, result, src_align_bytes, false);
2742827442 }
2742927443
......@@ -27444,7 +27458,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2744427458 // Keep the bigger alignment, it can only help-
2744527459 // unless the target is zero bits.
2744627460 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)) {
2744827462 result = ir_align_cast(ira, casted_ptr, src_align_bytes, false);
2744927463 if (type_is_invalid(result->value->type))
2745027464 return ira->codegen->invalid_inst_gen;
......@@ -27802,9 +27816,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2780227816 Error err;
2780327817
2780427818 ZigType *src_type = value->value->type;
27805 ir_assert(get_codegen_ptr_type(src_type) == nullptr, source_instr);
2780627819 ir_assert(type_can_bit_cast(src_type), source_instr);
27807 ir_assert(get_codegen_ptr_type(dest_type) == nullptr, source_instr);
2780827820 ir_assert(type_can_bit_cast(dest_type), source_instr);
2780927821
2781027822 if (dest_type->id == ZigTypeIdEnum) {
......@@ -27863,7 +27875,7 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir
2786327875 Error err;
2786427876
2786527877 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
2786827880 IrInstGen *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);
2786927881 if (type_is_invalid(casted_int->value->type))
......@@ -27981,7 +27993,7 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr
2798127993 if (!val)
2798227994 return ira->codegen->invalid_inst_gen;
2798327995
27984 // Since we've already run this type trough get_codegen_ptr_type it is
27996 // Since we've already run this type trough get_src_ptr_type it is
2798527997 // safe to access the x_ptr fields
2798627998 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
2798727999 IrInstGen *result = ir_const(ira, &instruction->base.base, usize);
......@@ -28232,10 +28244,17 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
2823228244 max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count));
2823328245 return ira->codegen->builtin_types.entry_invalid;
2823428246 }
28235 } else if (get_codegen_ptr_type(operand_type) == nullptr) {
28236 ir_add_error(ira, &op->base,
28237 buf_sprintf("expected integer, float, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));
28238 return ira->codegen->builtin_types.entry_invalid;
28247 } else {
28248 Error err;
28249 ZigType *operand_ptr_type;
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 }
2823928258 }
2824028259
2824128260 return operand_type;
......@@ -28666,15 +28685,19 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
2866628685 if (type_is_invalid(uncasted_op->value->type))
2866728686 return ira->codegen->invalid_inst_gen;
2866828687
28669 uint32_t vector_len; // UINT32_MAX means not a vector
28670 if (uncasted_op->value->type->id == ZigTypeIdArray &&
28671 is_valid_vector_elem_type(uncasted_op->value->type->data.array.child_type))
28672 {
28673 vector_len = uncasted_op->value->type->data.array.len;
28688 uint32_t vector_len = UINT32_MAX; // means not a vector
28689 if (uncasted_op->value->type->id == ZigTypeIdArray) {
28690 bool can_be_vec_elem;
28691 if ((err = is_valid_vector_elem_type(ira->codegen, uncasted_op->value->type->data.array.child_type,
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 }
2867428699 } else if (uncasted_op->value->type->id == ZigTypeIdVector) {
2867528700 vector_len = uncasted_op->value->type->data.vector.len;
28676 } else {
28677 vector_len = UINT32_MAX;
2867828701 }
2867928702
2868028703 bool is_vector = (vector_len != UINT32_MAX);
......@@ -29075,7 +29098,7 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i
2907529098 }
2907629099
2907729100 IrInstGen *result_loc;
29078 if (type_has_bits(result_type)) {
29101 if (type_has_bits(ira->codegen, result_type)) {
2907929102 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2908029103 result_type, nullptr, true, true);
2908129104 if (result_loc != nullptr &&
......@@ -29125,7 +29148,7 @@ static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSp
2912529148 if (type_is_invalid(operand->value->type))
2912629149 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))
2912929152 return ir_const_void(ira, &instruction->base.base);
2913029153
2913129154 switch (instruction->spill_id) {
......@@ -29145,7 +29168,7 @@ static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpil
2914529168 return ira->codegen->invalid_inst_gen;
2914629169
2914729170 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) ||
2914929172 instr_is_comptime(operand))
2915029173 {
2915129174 return operand;
......@@ -30188,7 +30211,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
3018830211 if (align_bytes != 0) {
3018930212 if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusAlignmentKnown)))
3019030213 return err;
30191 if (!type_has_bits(elem_type))
30214 if (!type_has_bits(ira->codegen, elem_type))
3019230215 align_bytes = 0;
3019330216 }
3019430217 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" {
786786 };
787787 S.doTheTest();
788788}
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}