authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-24 15:17:55-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-24 15:17:55-05:00
log44b1dc6db856e1d77ccf12c754351bda0c53804c
tree4ea04ef8043575caab9fb1ff8db0d5c677493ea7
parent4c7b52503b064b8be2f2afd4152311aff1941d92
signaturelock-open Commit is signed but in an unrecognized format.

add type coercion: [:x]T to [*:x]T


3 files changed, 260 insertions(+), 159 deletions(-)

lib/std/special/test_runner.zig+1-1
...@@ -36,7 +36,7 @@ pub fn main() anyerror!void {...@@ -36,7 +36,7 @@ pub fn main() anyerror!void {
36 }36 }
37 root_node.end();37 root_node.end();
38 if (ok_count == test_fn_list.len) {38 if (ok_count == test_fn_list.len) {
39 std.debug.warn("All tests passed.\n");39 std.debug.warn("All {} tests passed.\n", ok_count);
40 } else {40 } else {
41 std.debug.warn("{} passed; {} skipped.\n", ok_count, skip_count);41 std.debug.warn("{} passed; {} skipped.\n", ok_count, skip_count);
42 }42 }
src/ir.cpp+206-158
...@@ -188,7 +188,8 @@ struct ConstCastPtrSentinel {...@@ -188,7 +188,8 @@ struct ConstCastPtrSentinel {
188static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);188static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
189static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,189static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,
190 ResultLoc *result_loc);190 ResultLoc *result_loc);
191static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type);191static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,
192 IrInstruction *value, ZigType *expected_type);
192static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,193static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,
193 ResultLoc *result_loc);194 ResultLoc *result_loc);
194static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);195static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);
...@@ -11717,7 +11718,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so...@@ -11717,7 +11718,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
1171711718
11718 if (instr_is_comptime(value)) {11719 if (instr_is_comptime(value)) {
11719 ZigType *payload_type = wanted_type->data.maybe.child_type;11720 ZigType *payload_type = wanted_type->data.maybe.child_type;
11720 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);11721 IrInstruction *casted_payload = ir_implicit_cast(ira, source_instr, value, payload_type);
11721 if (type_is_invalid(casted_payload->value.type))11722 if (type_is_invalid(casted_payload->value.type))
11722 return ira->codegen->invalid_instruction;11723 return ira->codegen->invalid_instruction;
1172311724
...@@ -11760,7 +11761,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction...@@ -11760,7 +11761,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
11760 ZigType *payload_type = wanted_type->data.error_union.payload_type;11761 ZigType *payload_type = wanted_type->data.error_union.payload_type;
11761 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;11762 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
11762 if (instr_is_comptime(value)) {11763 if (instr_is_comptime(value)) {
11763 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);11764 IrInstruction *casted_payload = ir_implicit_cast(ira, source_instr, value, payload_type);
11764 if (type_is_invalid(casted_payload->value.type))11765 if (type_is_invalid(casted_payload->value.type))
11765 return ira->codegen->invalid_instruction;11766 return ira->codegen->invalid_instruction;
1176611767
...@@ -11880,7 +11881,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so...@@ -11880,7 +11881,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
11880{11881{
11881 assert(wanted_type->id == ZigTypeIdErrorUnion);11882 assert(wanted_type->id == ZigTypeIdErrorUnion);
1188211883
11883 IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);11884 IrInstruction *casted_value = ir_implicit_cast(ira, source_instr, value, wanted_type->data.error_union.err_set_type);
1188411885
11885 if (instr_is_comptime(casted_value)) {11886 if (instr_is_comptime(casted_value)) {
11886 ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad);11887 ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad);
...@@ -12065,7 +12066,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -12065,7 +12066,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
12065 enum_type = ir_resolve_union_tag_type(ira, target, target->value.type);12066 enum_type = ir_resolve_union_tag_type(ira, target, target->value.type);
12066 if (type_is_invalid(enum_type))12067 if (type_is_invalid(enum_type))
12067 return ira->codegen->invalid_instruction;12068 return ira->codegen->invalid_instruction;
12068 enum_target = ir_implicit_cast(ira, target, enum_type);12069 enum_target = ir_implicit_cast(ira, source_instr, target, enum_type);
12069 if (type_is_invalid(enum_target->value.type))12070 if (type_is_invalid(enum_target->value.type))
12070 return ira->codegen->invalid_instruction;12071 return ira->codegen->invalid_instruction;
12071 } else if (target->value.type->id == ZigTypeIdEnum) {12072 } else if (target->value.type->id == ZigTypeIdEnum) {
...@@ -12161,7 +12162,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -12161,7 +12162,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
12161 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusZeroBitsKnown)))12162 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusZeroBitsKnown)))
12162 return ira->codegen->invalid_instruction;12163 return ira->codegen->invalid_instruction;
1216312164
12164 IrInstruction *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type);12165 IrInstruction *target = ir_implicit_cast(ira, source_instr, uncasted_target, wanted_type->data.unionation.tag_type);
12165 if (type_is_invalid(target->value.type))12166 if (type_is_invalid(target->value.type))
12166 return ira->codegen->invalid_instruction;12167 return ira->codegen->invalid_instruction;
1216712168
...@@ -12824,8 +12825,55 @@ static IrInstruction *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInstr...@@ -12824,8 +12825,55 @@ static IrInstruction *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInstr
12824 return ira->codegen->invalid_instruction;12825 return ira->codegen->invalid_instruction;
12825}12826}
1282612827
12828// Add a compile error and return ErrorSemanticAnalyzeFail if the pointer alignment does not work,
12829// otherwise return ErrorNone. Does not emit any instructions.
12830// Assumes that the pointer types have element types with the same ABI alignment. Avoids resolving the
12831// pointer types' alignments if both of the pointer types are ABI aligned.
12832static Error ir_cast_ptr_align(IrAnalyze *ira, IrInstruction *source_instr, ZigType *dest_ptr_type,
12833 ZigType *src_ptr_type, AstNode *src_source_node)
12834{
12835 Error err;
12836
12837 ir_assert(dest_ptr_type->id == ZigTypeIdPointer, source_instr);
12838 ir_assert(src_ptr_type->id == ZigTypeIdPointer, source_instr);
12839
12840 if (dest_ptr_type->data.pointer.explicit_alignment == 0 &&
12841 src_ptr_type->data.pointer.explicit_alignment == 0)
12842 {
12843 return ErrorNone;
12844 }
12845
12846 if ((err = type_resolve(ira->codegen, dest_ptr_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
12847 return ErrorSemanticAnalyzeFail;
12848
12849 if ((err = type_resolve(ira->codegen, src_ptr_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
12850 return ErrorSemanticAnalyzeFail;
12851
12852 uint32_t wanted_align = get_ptr_align(ira->codegen, dest_ptr_type);
12853 uint32_t actual_align = get_ptr_align(ira->codegen, src_ptr_type);
12854 if (wanted_align > actual_align) {
12855 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment"));
12856 add_error_note(ira->codegen, msg, src_source_node,
12857 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_ptr_type->name), actual_align));
12858 add_error_note(ira->codegen, msg, source_instr->source_node,
12859 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_ptr_type->name), wanted_align));
12860 return ErrorSemanticAnalyzeFail;
12861 }
12862
12863 return ErrorNone;
12864}
12865
12866static IrInstruction *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInstruction *source_instr,
12867 IrInstruction *struct_operand, TypeStructField *field)
12868{
12869 IrInstruction *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false);
12870 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr,
12871 struct_operand->value.type, false);
12872 return ir_get_deref(ira, source_instr, field_ptr, nullptr);
12873}
12874
12827static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr,12875static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr,
12828 ZigType *wanted_type, IrInstruction *value, ResultLoc *result_loc)12876 ZigType *wanted_type, IrInstruction *value)
12829{12877{
12830 Error err;12878 Error err;
12831 ZigType *actual_type = value->value.type;12879 ZigType *actual_type = value->value.type;
...@@ -12871,12 +12919,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -12871,12 +12919,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
12871 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node,12919 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node,
12872 false).id == ConstCastResultIdOk)12920 false).id == ConstCastResultIdOk)
12873 {12921 {
12874 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, result_loc);12922 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);
12875 } else if (actual_type->id == ZigTypeIdComptimeInt ||12923 } else if (actual_type->id == ZigTypeIdComptimeInt ||
12876 actual_type->id == ZigTypeIdComptimeFloat)12924 actual_type->id == ZigTypeIdComptimeFloat)
12877 {12925 {
12878 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {12926 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {
12879 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, result_loc);12927 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);
12880 } else {12928 } else {
12881 return ira->codegen->invalid_instruction;12929 return ira->codegen->invalid_instruction;
12882 }12930 }
...@@ -12900,7 +12948,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -12900,7 +12948,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
12900 wanted_child_type);12948 wanted_child_type);
12901 if (type_is_invalid(cast1->value.type))12949 if (type_is_invalid(cast1->value.type))
12902 return ira->codegen->invalid_instruction;12950 return ira->codegen->invalid_instruction;
12903 return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, result_loc);12951 return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr);
12904 }12952 }
12905 }12953 }
12906 }12954 }
...@@ -12910,12 +12958,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -12910,12 +12958,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
12910 if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type,12958 if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type,
12911 source_node, false).id == ConstCastResultIdOk)12959 source_node, false).id == ConstCastResultIdOk)
12912 {12960 {
12913 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, result_loc);12961 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);
12914 } else if (actual_type->id == ZigTypeIdComptimeInt ||12962 } else if (actual_type->id == ZigTypeIdComptimeInt ||
12915 actual_type->id == ZigTypeIdComptimeFloat)12963 actual_type->id == ZigTypeIdComptimeFloat)
12916 {12964 {
12917 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {12965 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {
12918 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, result_loc);12966 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);
12919 } else {12967 } else {
12920 return ira->codegen->invalid_instruction;12968 return ira->codegen->invalid_instruction;
12921 }12969 }
...@@ -12933,11 +12981,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -12933,11 +12981,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
12933 actual_type->id == ZigTypeIdComptimeInt ||12981 actual_type->id == ZigTypeIdComptimeInt ||
12934 actual_type->id == ZigTypeIdComptimeFloat)12982 actual_type->id == ZigTypeIdComptimeFloat)
12935 {12983 {
12936 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value, nullptr);12984 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
12937 if (type_is_invalid(cast1->value.type))12985 if (type_is_invalid(cast1->value.type))
12938 return ira->codegen->invalid_instruction;12986 return ira->codegen->invalid_instruction;
1293912987
12940 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1, result_loc);12988 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
12941 if (type_is_invalid(cast2->value.type))12989 if (type_is_invalid(cast2->value.type))
12942 return ira->codegen->invalid_instruction;12990 return ira->codegen->invalid_instruction;
1294312991
...@@ -13019,7 +13067,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13019,7 +13067,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13019 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,13067 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
13020 source_node, false).id == ConstCastResultIdOk)13068 source_node, false).id == ConstCastResultIdOk)
13021 {13069 {
13022 return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type, result_loc);13070 return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type, nullptr);
13023 }13071 }
13024 }13072 }
1302513073
...@@ -13036,11 +13084,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13036,11 +13084,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13036 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,13084 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
13037 source_node, false).id == ConstCastResultIdOk)13085 source_node, false).id == ConstCastResultIdOk)
13038 {13086 {
13039 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value, nullptr);13087 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
13040 if (type_is_invalid(cast1->value.type))13088 if (type_is_invalid(cast1->value.type))
13041 return ira->codegen->invalid_instruction;13089 return ira->codegen->invalid_instruction;
1304213090
13043 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1, result_loc);13091 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13044 if (type_is_invalid(cast2->value.type))13092 if (type_is_invalid(cast2->value.type))
13045 return ira->codegen->invalid_instruction;13093 return ira->codegen->invalid_instruction;
1304613094
...@@ -13055,11 +13103,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13055,11 +13103,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13055 actual_type->data.pointer.ptr_len == PtrLenSingle &&13103 actual_type->data.pointer.ptr_len == PtrLenSingle &&
13056 actual_type->data.pointer.child_type->id == ZigTypeIdArray)13104 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
13057 {13105 {
13058 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value, nullptr);13106 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
13059 if (type_is_invalid(cast1->value.type))13107 if (type_is_invalid(cast1->value.type))
13060 return ira->codegen->invalid_instruction;13108 return ira->codegen->invalid_instruction;
1306113109
13062 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1, result_loc);13110 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13063 if (type_is_invalid(cast2->value.type))13111 if (type_is_invalid(cast2->value.type))
13064 return ira->codegen->invalid_instruction;13112 return ira->codegen->invalid_instruction;
1306513113
...@@ -13136,17 +13184,17 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13136,17 +13184,17 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13136 }13184 }
13137 if (ok_align) {13185 if (ok_align) {
13138 if (wanted_type->id == ZigTypeIdErrorUnion) {13186 if (wanted_type->id == ZigTypeIdErrorUnion) {
13139 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value, nullptr);13187 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value);
13140 if (type_is_invalid(cast1->value.type))13188 if (type_is_invalid(cast1->value.type))
13141 return ira->codegen->invalid_instruction;13189 return ira->codegen->invalid_instruction;
1314213190
13143 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1, result_loc);13191 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13144 if (type_is_invalid(cast2->value.type))13192 if (type_is_invalid(cast2->value.type))
13145 return ira->codegen->invalid_instruction;13193 return ira->codegen->invalid_instruction;
1314613194
13147 return cast2;13195 return cast2;
13148 } else {13196 } else {
13149 return ir_resolve_ptr_of_array_to_slice(ira, source_instr, value, slice_type, result_loc);13197 return ir_resolve_ptr_of_array_to_slice(ira, source_instr, value, slice_type, nullptr);
13150 }13198 }
13151 }13199 }
13152 }13200 }
...@@ -13187,7 +13235,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13187,7 +13235,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13187 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);13235 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);
13188 }13236 }
13189 if (ok_align) {13237 if (ok_align) {
13190 return ir_resolve_ptr_of_array_to_slice(ira, source_instr, value, slice_type, result_loc);13238 return ir_resolve_ptr_of_array_to_slice(ira, source_instr, value, slice_type, nullptr);
13191 }13239 }
13192 }13240 }
13193 }13241 }
...@@ -13243,11 +13291,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13243,11 +13291,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13243 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,13291 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
13244 source_node, false).id == ConstCastResultIdOk)13292 source_node, false).id == ConstCastResultIdOk)
13245 {13293 {
13246 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value, nullptr);13294 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
13247 if (type_is_invalid(cast1->value.type))13295 if (type_is_invalid(cast1->value.type))
13248 return ira->codegen->invalid_instruction;13296 return ira->codegen->invalid_instruction;
1324913297
13250 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1, result_loc);13298 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13251 if (type_is_invalid(cast2->value.type))13299 if (type_is_invalid(cast2->value.type))
13252 return ira->codegen->invalid_instruction;13300 return ira->codegen->invalid_instruction;
1325313301
...@@ -13259,7 +13307,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13259,7 +13307,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13259 if (wanted_type->id == ZigTypeIdErrorUnion &&13307 if (wanted_type->id == ZigTypeIdErrorUnion &&
13260 actual_type->id == ZigTypeIdErrorSet)13308 actual_type->id == ZigTypeIdErrorSet)
13261 {13309 {
13262 return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type, result_loc);13310 return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type, nullptr);
13263 }13311 }
1326413312
13265 // cast from typed number to integer or float literal.13313 // cast from typed number to integer or float literal.
...@@ -13285,7 +13333,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13285,7 +13333,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13285 if (result == ira->codegen->invalid_instruction) 13333 if (result == ira->codegen->invalid_instruction)
13286 return result;13334 return result;
1328713335
13288 return ir_analyze_optional_wrap(ira, result, value, wanted_type, result_loc);13336 return ir_analyze_optional_wrap(ira, result, value, wanted_type, nullptr);
13289 }13337 }
1329013338
13291 // cast from enum literal to error union when payload is an enum13339 // cast from enum literal to error union when payload is an enum
...@@ -13296,7 +13344,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13296,7 +13344,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13296 if (result == ira->codegen->invalid_instruction) 13344 if (result == ira->codegen->invalid_instruction)
13297 return result;13345 return result;
13298 13346
13299 return ir_analyze_err_wrap_payload(ira, result, value, wanted_type, result_loc);13347 return ir_analyze_err_wrap_payload(ira, result, value, wanted_type, nullptr);
13300 }13348 }
1330113349
13302 // cast from union to the enum type of the union13350 // cast from union to the enum type of the union
...@@ -13326,35 +13374,39 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13326,35 +13374,39 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13326 types_match_const_cast_only(ira, array_type->data.array.child_type,13374 types_match_const_cast_only(ira, array_type->data.array.child_type,
13327 actual_type->data.pointer.child_type, source_node,13375 actual_type->data.pointer.child_type, source_node,
13328 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk &&13376 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk &&
13329 // This should be the job of `types_match_const_cast_only`13377 // `types_match_const_cast_only` only gets info for child_types
13330 // but `types_match_const_cast_only` only gets info for child_types13378 (!wanted_type->data.pointer.is_const || actual_type->data.pointer.is_const) &&
13331 ((wanted_type->data.pointer.is_const && actual_type->data.pointer.is_const) ||13379 (!wanted_type->data.pointer.is_volatile || actual_type->data.pointer.is_volatile))
13332 !actual_type->data.pointer.is_const))
13333 {13380 {
13334 if ((err = type_resolve(ira->codegen, wanted_type->data.pointer.child_type,13381 if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->source_node)))
13335 ResolveStatusAlignmentKnown)))
13336 {
13337 return ira->codegen->invalid_instruction;
13338 }
13339 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,
13340 ResolveStatusAlignmentKnown)))
13341 {
13342 return ira->codegen->invalid_instruction;
13343 }
13344 uint32_t wanted_align = get_ptr_align(ira->codegen, wanted_type);
13345 uint32_t actual_align = get_ptr_align(ira->codegen, actual_type);
13346 if (wanted_align > actual_align) {
13347 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment"));
13348 add_error_note(ira->codegen, msg, value->source_node,
13349 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&actual_type->name), actual_align));
13350 add_error_note(ira->codegen, msg, source_instr->source_node,
13351 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&wanted_type->name), wanted_align));
13352 return ira->codegen->invalid_instruction;13382 return ira->codegen->invalid_instruction;
13353 }13383
13354 return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type);13384 return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type);
13355 }13385 }
13356 }13386 }
1335713387
13388 // [:x]T to [*:x]T
13389 // [:x]T to [*c]T
13390 if (wanted_type->id == ZigTypeIdPointer && is_slice(actual_type) &&
13391 ((wanted_type->data.pointer.ptr_len == PtrLenUnknown && wanted_type->data.pointer.sentinel != nullptr) ||
13392 wanted_type->data.pointer.ptr_len == PtrLenC))
13393 {
13394 ZigType *slice_ptr_type = resolve_struct_field_type(ira->codegen,
13395 actual_type->data.structure.fields[slice_ptr_index]);
13396 if (types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
13397 slice_ptr_type->data.pointer.child_type, source_node,
13398 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk &&
13399 (slice_ptr_type->data.pointer.sentinel != nullptr &&
13400 (wanted_type->data.pointer.ptr_len == PtrLenC ||
13401 const_values_equal(ira->codegen, wanted_type->data.pointer.sentinel,
13402 slice_ptr_type->data.pointer.sentinel))))
13403 {
13404 TypeStructField *ptr_field = actual_type->data.structure.fields[slice_ptr_index];
13405 IrInstruction *slice_ptr = ir_analyze_struct_value_field_value(ira, source_instr, value, ptr_field);
13406 return ir_implicit_cast(ira, source_instr, slice_ptr, wanted_type);
13407 }
13408 }
13409
13358 // cast from *T and [*]T to *c_void and ?*c_void13410 // cast from *T and [*]T to *c_void and ?*c_void
13359 // but don't do it if the actual type is a double pointer13411 // but don't do it if the actual type is a double pointer
13360 if (is_pointery_and_elem_is_not_pointery(actual_type)) {13412 if (is_pointery_and_elem_is_not_pointery(actual_type)) {
...@@ -13393,7 +13445,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13393,7 +13445,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13393 types_match_const_cast_only(ira, wanted_type->data.array.child_type,13445 types_match_const_cast_only(ira, wanted_type->data.array.child_type,
13394 actual_type->data.vector.elem_type, source_node, false).id == ConstCastResultIdOk)13446 actual_type->data.vector.elem_type, source_node, false).id == ConstCastResultIdOk)
13395 {13447 {
13396 return ir_analyze_vector_to_array(ira, source_instr, value, wanted_type, result_loc);13448 return ir_analyze_vector_to_array(ira, source_instr, value, wanted_type, nullptr);
13397 }13449 }
1339813450
13399 // cast from [N]T to @Vector(N, T)13451 // cast from [N]T to @Vector(N, T)
...@@ -13454,8 +13506,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13454,8 +13506,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13454 return ira->codegen->invalid_instruction;13506 return ira->codegen->invalid_instruction;
13455}13507}
1345613508
13457static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction *source_instr,13509static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,
13458 IrInstruction *value, ZigType *expected_type, ResultLoc *result_loc)13510 IrInstruction *value, ZigType *expected_type)
13459{13511{
13460 assert(value);13512 assert(value);
13461 assert(value != ira->codegen->invalid_instruction);13513 assert(value != ira->codegen->invalid_instruction);
...@@ -13469,11 +13521,7 @@ static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction...@@ -13469,11 +13521,7 @@ static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction
13469 if (value->value.type->id == ZigTypeIdUnreachable)13521 if (value->value.type->id == ZigTypeIdUnreachable)
13470 return value;13522 return value;
1347113523
13472 return ir_analyze_cast(ira, source_instr, expected_type, value, result_loc);13524 return ir_analyze_cast(ira, source_instr, expected_type, value);
13473}
13474
13475static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) {
13476 return ir_implicit_cast_with_result(ira, value, value, expected_type, nullptr);
13477}13525}
1347813526
13479static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,13527static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,
...@@ -13611,7 +13659,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem...@@ -13611,7 +13659,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem
13611 }13659 }
13612 }13660 }
1361313661
13614 IrInstruction *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen));13662 IrInstruction *casted_value = ir_implicit_cast(ira, value, value, get_align_amt_type(ira->codegen));
13615 if (type_is_invalid(casted_value->value.type))13663 if (type_is_invalid(casted_value->value.type))
13616 return false;13664 return false;
1361713665
...@@ -13623,7 +13671,7 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i...@@ -13623,7 +13671,7 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i
13623 if (type_is_invalid(value->value.type))13671 if (type_is_invalid(value->value.type))
13624 return false;13672 return false;
1362513673
13626 IrInstruction *casted_value = ir_implicit_cast(ira, value, int_type);13674 IrInstruction *casted_value = ir_implicit_cast(ira, value, value, int_type);
13627 if (type_is_invalid(casted_value->value.type))13675 if (type_is_invalid(casted_value->value.type))
13628 return false;13676 return false;
1362913677
...@@ -13643,7 +13691,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {...@@ -13643,7 +13691,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
13643 if (type_is_invalid(value->value.type))13691 if (type_is_invalid(value->value.type))
13644 return false;13692 return false;
1364513693
13646 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);13694 IrInstruction *casted_value = ir_implicit_cast(ira, value, value, ira->codegen->builtin_types.entry_bool);
13647 if (type_is_invalid(casted_value->value.type))13695 if (type_is_invalid(casted_value->value.type))
13648 return false;13696 return false;
1364913697
...@@ -13671,7 +13719,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic...@@ -13671,7 +13719,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
13671 assert(atomic_order_val->type->id == ZigTypeIdMetaType);13719 assert(atomic_order_val->type->id == ZigTypeIdMetaType);
13672 ZigType *atomic_order_type = atomic_order_val->data.x_type;13720 ZigType *atomic_order_type = atomic_order_val->data.x_type;
1367313721
13674 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type);13722 IrInstruction *casted_value = ir_implicit_cast(ira, value, value, atomic_order_type);
13675 if (type_is_invalid(casted_value->value.type))13723 if (type_is_invalid(casted_value->value.type))
13676 return false;13724 return false;
1367713725
...@@ -13691,7 +13739,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi...@@ -13691,7 +13739,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
13691 assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType);13739 assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType);
13692 ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;13740 ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;
1369313741
13694 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);13742 IrInstruction *casted_value = ir_implicit_cast(ira, value, value, atomic_rmw_op_type);
13695 if (type_is_invalid(casted_value->value.type))13743 if (type_is_invalid(casted_value->value.type))
13696 return false;13744 return false;
1369713745
...@@ -13711,7 +13759,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob...@@ -13711,7 +13759,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
13711 assert(global_linkage_val->type->id == ZigTypeIdMetaType);13759 assert(global_linkage_val->type->id == ZigTypeIdMetaType);
13712 ZigType *global_linkage_type = global_linkage_val->data.x_type;13760 ZigType *global_linkage_type = global_linkage_val->data.x_type;
1371313761
13714 IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type);13762 IrInstruction *casted_value = ir_implicit_cast(ira, value, value, global_linkage_type);
13715 if (type_is_invalid(casted_value->value.type))13763 if (type_is_invalid(casted_value->value.type))
13716 return false;13764 return false;
1371713765
...@@ -13731,7 +13779,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod...@@ -13731,7 +13779,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
13731 assert(float_mode_val->type->id == ZigTypeIdMetaType);13779 assert(float_mode_val->type->id == ZigTypeIdMetaType);
13732 ZigType *float_mode_type = float_mode_val->data.x_type;13780 ZigType *float_mode_type = float_mode_val->data.x_type;
1373313781
13734 IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type);13782 IrInstruction *casted_value = ir_implicit_cast(ira, value, value, float_mode_type);
13735 if (type_is_invalid(casted_value->value.type))13783 if (type_is_invalid(casted_value->value.type))
13736 return false;13784 return false;
1373713785
...@@ -13750,7 +13798,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -13750,7 +13798,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
13750 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,13798 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
13751 true, false, PtrLenUnknown, 0, 0, 0, false);13799 true, false, PtrLenUnknown, 0, 0, 0, false);
13752 ZigType *str_type = get_slice_type(ira->codegen, ptr_type);13800 ZigType *str_type = get_slice_type(ira->codegen, ptr_type);
13753 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);13801 IrInstruction *casted_value = ir_implicit_cast(ira, value, value, str_type);
13754 if (type_is_invalid(casted_value->value.type))13802 if (type_is_invalid(casted_value->value.type))
13755 return nullptr;13803 return nullptr;
1375613804
...@@ -13814,7 +13862,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio...@@ -13814,7 +13862,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
13814 return ir_finish_anal(ira, result);13862 return ir_finish_anal(ira, result);
13815 }13863 }
1381613864
13817 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type);13865 IrInstruction *casted_operand = ir_implicit_cast(ira, &instruction->base, operand, ira->explicit_return_type);
13818 if (type_is_invalid(casted_operand->value.type)) {13866 if (type_is_invalid(casted_operand->value.type)) {
13819 AstNode *source_node = ira->explicit_return_type_source_node;13867 AstNode *source_node = ira->explicit_return_type_source_node;
13820 if (source_node != nullptr) {13868 if (source_node != nullptr) {
...@@ -13856,11 +13904,11 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp...@@ -13856,11 +13904,11 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
1385613904
13857 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;13905 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
1385813906
13859 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type);13907 IrInstruction *casted_op1 = ir_implicit_cast(ira, &bin_op_instruction->base, op1, bool_type);
13860 if (casted_op1 == ira->codegen->invalid_instruction)13908 if (casted_op1 == ira->codegen->invalid_instruction)
13861 return ira->codegen->invalid_instruction;13909 return ira->codegen->invalid_instruction;
1386213910
13863 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, bool_type);13911 IrInstruction *casted_op2 = ir_implicit_cast(ira, &bin_op_instruction->base, op2, bool_type);
13864 if (casted_op2 == ira->codegen->invalid_instruction)13912 if (casted_op2 == ira->codegen->invalid_instruction)
13865 return ira->codegen->invalid_instruction;13913 return ira->codegen->invalid_instruction;
1386613914
...@@ -14129,11 +14177,11 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14129,11 +14177,11 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14129 ZigType *tag_type = union_val->value.type->data.unionation.tag_type;14177 ZigType *tag_type = union_val->value.type->data.unionation.tag_type;
14130 assert(tag_type != nullptr);14178 assert(tag_type != nullptr);
1413114179
14132 IrInstruction *casted_union = ir_implicit_cast(ira, union_val, tag_type);14180 IrInstruction *casted_union = ir_implicit_cast(ira, &bin_op_instruction->base, union_val, tag_type);
14133 if (type_is_invalid(casted_union->value.type))14181 if (type_is_invalid(casted_union->value.type))
14134 return ira->codegen->invalid_instruction;14182 return ira->codegen->invalid_instruction;
1413514183
14136 IrInstruction *casted_val = ir_implicit_cast(ira, enum_val, tag_type);14184 IrInstruction *casted_val = ir_implicit_cast(ira, &bin_op_instruction->base, enum_val, tag_type);
14137 if (type_is_invalid(casted_val->value.type))14185 if (type_is_invalid(casted_val->value.type))
14138 return ira->codegen->invalid_instruction;14186 return ira->codegen->invalid_instruction;
1413914187
...@@ -14296,11 +14344,11 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -14296,11 +14344,11 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
14296 return ira->codegen->invalid_instruction;14344 return ira->codegen->invalid_instruction;
14297 }14345 }
1429814346
14299 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);14347 IrInstruction *casted_op1 = ir_implicit_cast(ira, &bin_op_instruction->base, op1, resolved_type);
14300 if (casted_op1 == ira->codegen->invalid_instruction)14348 if (casted_op1 == ira->codegen->invalid_instruction)
14301 return ira->codegen->invalid_instruction;14349 return ira->codegen->invalid_instruction;
1430214350
14303 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);14351 IrInstruction *casted_op2 = ir_implicit_cast(ira, &bin_op_instruction->base, op2, resolved_type);
14304 if (casted_op2 == ira->codegen->invalid_instruction)14352 if (casted_op2 == ira->codegen->invalid_instruction)
14305 return ira->codegen->invalid_instruction;14353 return ira->codegen->invalid_instruction;
1430614354
...@@ -14648,7 +14696,7 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i...@@ -14648,7 +14696,7 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i
14648 return ira->codegen->invalid_instruction;14696 return ira->codegen->invalid_instruction;
14649 }14697 }
14650 }14698 }
14651 return ir_implicit_cast(ira, result_instruction, type_entry);14699 return ir_implicit_cast(ira, source_instr, result_instruction, type_entry);
14652}14700}
1465314701
14654static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {14702static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
...@@ -14713,7 +14761,7 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b...@@ -14713,7 +14761,7 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b
14713 }14761 }
14714 }14762 }
1471514763
14716 casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type);14764 casted_op2 = ir_implicit_cast(ira, &bin_op_instruction->base, op2, shift_amt_type);
14717 if (casted_op2 == ira->codegen->invalid_instruction)14765 if (casted_op2 == ira->codegen->invalid_instruction)
14718 return ira->codegen->invalid_instruction;14766 return ira->codegen->invalid_instruction;
14719 }14767 }
...@@ -14822,7 +14870,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -14822,7 +14870,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1482214870
14823 // look for pointer math14871 // look for pointer math
14824 if (is_pointer_arithmetic_allowed(op1->value.type, op_id)) {14872 if (is_pointer_arithmetic_allowed(op1->value.type, op_id)) {
14825 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);14873 IrInstruction *casted_op2 = ir_implicit_cast(ira, &instruction->base, op2, ira->codegen->builtin_types.entry_usize);
14826 if (type_is_invalid(casted_op2->value.type))14874 if (type_is_invalid(casted_op2->value.type))
14827 return ira->codegen->invalid_instruction;14875 return ira->codegen->invalid_instruction;
1482814876
...@@ -14958,7 +15006,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -14958,7 +15006,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
14958 ok = bigint_cmp(&rem_result, &mod_result) == CmpEQ;15006 ok = bigint_cmp(&rem_result, &mod_result) == CmpEQ;
14959 }15007 }
14960 } else {15008 } else {
14961 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);15009 IrInstruction *casted_op2 = ir_implicit_cast(ira, &instruction->base, op2, resolved_type);
14962 if (casted_op2 == ira->codegen->invalid_instruction)15010 if (casted_op2 == ira->codegen->invalid_instruction)
14963 return ira->codegen->invalid_instruction;15011 return ira->codegen->invalid_instruction;
1496415012
...@@ -15022,11 +15070,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15022,11 +15070,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15022 }15070 }
15023 }15071 }
1502415072
15025 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);15073 IrInstruction *casted_op1 = ir_implicit_cast(ira, &instruction->base, op1, resolved_type);
15026 if (casted_op1 == ira->codegen->invalid_instruction)15074 if (casted_op1 == ira->codegen->invalid_instruction)
15027 return ira->codegen->invalid_instruction;15075 return ira->codegen->invalid_instruction;
1502815076
15029 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);15077 IrInstruction *casted_op2 = ir_implicit_cast(ira, &instruction->base, op2, resolved_type);
15030 if (casted_op2 == ira->codegen->invalid_instruction)15078 if (casted_op2 == ira->codegen->invalid_instruction)
15031 return ira->codegen->invalid_instruction;15079 return ira->codegen->invalid_instruction;
1503215080
...@@ -16239,7 +16287,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16239,7 +16287,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16239 // In this case we can pointer cast the result location.16287 // In this case we can pointer cast the result location.
16240 IrInstruction *casted_value;16288 IrInstruction *casted_value;
16241 if (value != nullptr) {16289 if (value != nullptr) {
16242 casted_value = ir_implicit_cast(ira, value, dest_type);16290 casted_value = ir_implicit_cast(ira, value, value, dest_type);
16243 } else {16291 } else {
16244 casted_value = nullptr;16292 casted_value = nullptr;
16245 }16293 }
...@@ -16530,7 +16578,7 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstructionCal...@@ -16530,7 +16578,7 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstructionCal
16530 // Result location will be inside the async frame.16578 // Result location will be inside the async frame.
16531 return nullptr;16579 return nullptr;
16532 }16580 }
16533 return ir_implicit_cast(ira, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false));16581 return ir_implicit_cast(ira, ret_ptr_uncasted, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false));
16534}16582}
1653516583
16536static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry,16584static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry,
...@@ -16567,7 +16615,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc...@@ -16567,7 +16615,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc
16567 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {16615 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
16568 return result_loc;16616 return result_loc;
16569 }16617 }
16570 result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false));16618 result_loc = ir_implicit_cast(ira, &call_instruction->base, result_loc, get_pointer_to_type(ira->codegen, frame_type, false));
16571 if (type_is_invalid(result_loc->value.type))16619 if (type_is_invalid(result_loc->value.type))
16572 return ira->codegen->invalid_instruction;16620 return ira->codegen->invalid_instruction;
16573 return &ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, arg_count,16621 return &ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, arg_count,
...@@ -16588,7 +16636,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node...@@ -16588,7 +16636,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
16588 if (type_is_invalid(param_type))16636 if (type_is_invalid(param_type))
16589 return false;16637 return false;
1659016638
16591 casted_arg = ir_implicit_cast(ira, arg, param_type);16639 casted_arg = ir_implicit_cast(ira, arg, arg, param_type);
16592 if (type_is_invalid(casted_arg->value.type))16640 if (type_is_invalid(casted_arg->value.type))
16593 return false;16641 return false;
16594 } else {16642 } else {
...@@ -16628,7 +16676,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -16628,7 +16676,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
16628 if (type_is_invalid(param_type))16676 if (type_is_invalid(param_type))
16629 return false;16677 return false;
1663016678
16631 casted_arg = ir_implicit_cast(ira, arg, param_type);16679 casted_arg = ir_implicit_cast(ira, arg, arg, param_type);
16632 if (type_is_invalid(casted_arg->value.type))16680 if (type_is_invalid(casted_arg->value.type))
16633 return false;16681 return false;
16634 } else {16682 } else {
...@@ -16869,7 +16917,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -16869,7 +16917,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
16869 }16917 }
1687016918
16871 ZigType *child_type = ptr->value.type->data.pointer.child_type;16919 ZigType *child_type = ptr->value.type->data.pointer.child_type;
16872 IrInstruction *value = ir_implicit_cast(ira, uncasted_value, child_type);16920 IrInstruction *value = ir_implicit_cast(ira, uncasted_value, uncasted_value, child_type);
16873 if (value == ira->codegen->invalid_instruction)16921 if (value == ira->codegen->invalid_instruction)
16874 return ira->codegen->invalid_instruction;16922 return ira->codegen->invalid_instruction;
1687516923
...@@ -16986,13 +17034,13 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstructionCall...@@ -16986,13 +17034,13 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstructionCall
16986 {17034 {
16987 ZigType *needed_frame_type = get_pointer_to_type(ira->codegen,17035 ZigType *needed_frame_type = get_pointer_to_type(ira->codegen,
16988 get_fn_frame_type(ira->codegen, fn_entry), false);17036 get_fn_frame_type(ira->codegen, fn_entry), false);
16989 return ir_implicit_cast(ira, new_stack, needed_frame_type);17037 return ir_implicit_cast(ira, &call_instruction->base, new_stack, needed_frame_type);
16990 } else {17038 } else {
16991 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,17039 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
16992 false, false, PtrLenUnknown, target_fn_align(ira->codegen->zig_target), 0, 0, false);17040 false, false, PtrLenUnknown, target_fn_align(ira->codegen->zig_target), 0, 0, false);
16993 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);17041 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
16994 ira->codegen->need_frame_size_prefix_data = true;17042 ira->codegen->need_frame_size_prefix_data = true;
16995 return ir_implicit_cast(ira, new_stack, u8_slice);17043 return ir_implicit_cast(ira, &call_instruction->base, new_stack, u8_slice);
16996 }17044 }
16997}17045}
1699817046
...@@ -17466,7 +17514,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17466,7 +17514,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17466 return ira->codegen->invalid_instruction;17514 return ira->codegen->invalid_instruction;
17467 }17515 }
1746817516
17469 IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type);17517 IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, first_arg, param_type);
17470 if (type_is_invalid(casted_arg->value.type))17518 if (type_is_invalid(casted_arg->value.type))
17471 return ira->codegen->invalid_instruction;17519 return ira->codegen->invalid_instruction;
1747217520
...@@ -17501,7 +17549,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17501,7 +17549,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17501 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;17549 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
17502 if (type_is_invalid(param_type))17550 if (type_is_invalid(param_type))
17503 return ira->codegen->invalid_instruction;17551 return ira->codegen->invalid_instruction;
17504 casted_arg = ir_implicit_cast(ira, arg_tuple_arg, param_type);17552 casted_arg = ir_implicit_cast(ira, arg_tuple_arg, arg_tuple_arg, param_type);
17505 if (type_is_invalid(casted_arg->value.type))17553 if (type_is_invalid(casted_arg->value.type))
17506 return ira->codegen->invalid_instruction;17554 return ira->codegen->invalid_instruction;
17507 } else {17555 } else {
...@@ -17517,7 +17565,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17517,7 +17565,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17517 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;17565 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
17518 if (type_is_invalid(param_type))17566 if (type_is_invalid(param_type))
17519 return ira->codegen->invalid_instruction;17567 return ira->codegen->invalid_instruction;
17520 casted_arg = ir_implicit_cast(ira, old_arg, param_type);17568 casted_arg = ir_implicit_cast(ira, old_arg, old_arg, param_type);
17521 if (type_is_invalid(casted_arg->value.type))17569 if (type_is_invalid(casted_arg->value.type))
17522 return ira->codegen->invalid_instruction;17570 return ira->codegen->invalid_instruction;
17523 } else {17571 } else {
...@@ -17949,7 +17997,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi...@@ -17949,7 +17997,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
17949 return ir_unreach_error(ira);17997 return ir_unreach_error(ira);
1795017998
17951 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;17999 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
17952 IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type);18000 IrInstruction *casted_condition = ir_implicit_cast(ira, &cond_br_instruction->base, condition, bool_type);
17953 if (type_is_invalid(casted_condition->value.type))18001 if (type_is_invalid(casted_condition->value.type))
17954 return ir_unreach_error(ira);18002 return ir_unreach_error(ira);
1795518003
...@@ -18199,7 +18247,7 @@ skip_resolve_peer_types:...@@ -18199,7 +18247,7 @@ skip_resolve_peer_types:
18199 ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base);18247 ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base);
18200 IrInstruction *branch_instruction = predecessor->instruction_list.pop();18248 IrInstruction *branch_instruction = predecessor->instruction_list.pop();
18201 ir_set_cursor_at_end(&ira->new_irb, predecessor);18249 ir_set_cursor_at_end(&ira->new_irb, predecessor);
18202 IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type);18250 IrInstruction *casted_value = ir_implicit_cast(ira, new_value, new_value, resolved_type);
18203 if (type_is_invalid(casted_value->value.type)) {18251 if (type_is_invalid(casted_value->value.type)) {
18204 return ira->codegen->invalid_instruction;18252 return ira->codegen->invalid_instruction;
18205 }18253 }
...@@ -18385,7 +18433,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18385,7 +18433,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18385 array_type->data.structure.resolve_status == ResolveStatusBeingInferred)18433 array_type->data.structure.resolve_status == ResolveStatusBeingInferred)
18386 {18434 {
18387 ZigType *usize = ira->codegen->builtin_types.entry_usize;18435 ZigType *usize = ira->codegen->builtin_types.entry_usize;
18388 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);18436 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, elem_index, usize);
18389 if (casted_elem_index == ira->codegen->invalid_instruction)18437 if (casted_elem_index == ira->codegen->invalid_instruction)
18390 return ira->codegen->invalid_instruction;18438 return ira->codegen->invalid_instruction;
18391 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base);18439 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base);
...@@ -18400,7 +18448,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18400,7 +18448,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18400 }18448 }
1840118449
18402 ZigType *usize = ira->codegen->builtin_types.entry_usize;18450 ZigType *usize = ira->codegen->builtin_types.entry_usize;
18403 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);18451 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, elem_index, usize);
18404 if (casted_elem_index == ira->codegen->invalid_instruction)18452 if (casted_elem_index == ira->codegen->invalid_instruction)
18405 return ira->codegen->invalid_instruction;18453 return ira->codegen->invalid_instruction;
1840618454
...@@ -19759,7 +19807,7 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -19759,7 +19807,7 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
19759 IrInstruction *uncasted_sentinel = array_type_instruction->sentinel->child;19807 IrInstruction *uncasted_sentinel = array_type_instruction->sentinel->child;
19760 if (type_is_invalid(uncasted_sentinel->value.type))19808 if (type_is_invalid(uncasted_sentinel->value.type))
19761 return ira->codegen->invalid_instruction;19809 return ira->codegen->invalid_instruction;
19762 IrInstruction *sentinel = ir_implicit_cast(ira, uncasted_sentinel, child_type);19810 IrInstruction *sentinel = ir_implicit_cast(ira, &array_type_instruction->base, uncasted_sentinel, child_type);
19763 if (type_is_invalid(sentinel->value.type))19811 if (type_is_invalid(sentinel->value.type))
19764 return ira->codegen->invalid_instruction;19812 return ira->codegen->invalid_instruction;
19765 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);19813 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
...@@ -20033,7 +20081,7 @@ static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCt...@@ -20033,7 +20081,7 @@ static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCt
20033 if (type_is_invalid(int_type))20081 if (type_is_invalid(int_type))
20034 return ira->codegen->invalid_instruction;20082 return ira->codegen->invalid_instruction;
2003520083
20036 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);20084 IrInstruction *op = ir_implicit_cast(ira, &instruction->base, instruction->op->child, int_type);
20037 if (type_is_invalid(op->value.type))20085 if (type_is_invalid(op->value.type))
20038 return ira->codegen->invalid_instruction;20086 return ira->codegen->invalid_instruction;
2003920087
...@@ -20062,7 +20110,7 @@ static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionCl...@@ -20062,7 +20110,7 @@ static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionCl
20062 if (type_is_invalid(int_type))20110 if (type_is_invalid(int_type))
20063 return ira->codegen->invalid_instruction;20111 return ira->codegen->invalid_instruction;
2006420112
20065 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);20113 IrInstruction *op = ir_implicit_cast(ira, &instruction->base, instruction->op->child, int_type);
20066 if (type_is_invalid(op->value.type))20114 if (type_is_invalid(op->value.type))
20067 return ira->codegen->invalid_instruction;20115 return ira->codegen->invalid_instruction;
2006820116
...@@ -20091,7 +20139,7 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc...@@ -20091,7 +20139,7 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc
20091 if (type_is_invalid(int_type))20139 if (type_is_invalid(int_type))
20092 return ira->codegen->invalid_instruction;20140 return ira->codegen->invalid_instruction;
2009320141
20094 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);20142 IrInstruction *op = ir_implicit_cast(ira, &instruction->base, instruction->op->child, int_type);
20095 if (type_is_invalid(op->value.type))20143 if (type_is_invalid(op->value.type))
20096 return ira->codegen->invalid_instruction;20144 return ira->codegen->invalid_instruction;
2009720145
...@@ -20201,7 +20249,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -20201,7 +20249,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
20201 return ir_unreach_error(ira);20249 return ir_unreach_error(ira);
20202 }20250 }
2020320251
20204 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value.type);20252 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, case_value, target_value->value.type);
20205 if (type_is_invalid(casted_case_value->value.type))20253 if (type_is_invalid(casted_case_value->value.type))
20206 return ir_unreach_error(ira);20254 return ir_unreach_error(ira);
2020720255
...@@ -20251,7 +20299,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -20251,7 +20299,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
20251 continue;20299 continue;
20252 }20300 }
2025320301
20254 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value.type);20302 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, new_value, target_value->value.type);
20255 if (type_is_invalid(casted_new_value->value.type))20303 if (type_is_invalid(casted_new_value->value.type))
20256 continue;20304 continue;
2025720305
...@@ -20421,7 +20469,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -20421,7 +20469,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
20421 if (type_is_invalid(first_prong_value->value.type))20469 if (type_is_invalid(first_prong_value->value.type))
20422 return ira->codegen->invalid_instruction;20470 return ira->codegen->invalid_instruction;
2042320471
20424 IrInstruction *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type);20472 IrInstruction *first_casted_prong_value = ir_implicit_cast(ira, &instruction->base, first_prong_value, enum_type);
20425 if (type_is_invalid(first_casted_prong_value->value.type))20473 if (type_is_invalid(first_casted_prong_value->value.type))
20426 return ira->codegen->invalid_instruction;20474 return ira->codegen->invalid_instruction;
2042720475
...@@ -20437,7 +20485,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -20437,7 +20485,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
20437 if (type_is_invalid(this_prong_inst->value.type))20485 if (type_is_invalid(this_prong_inst->value.type))
20438 return ira->codegen->invalid_instruction;20486 return ira->codegen->invalid_instruction;
2043920487
20440 IrInstruction *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type);20488 IrInstruction *this_casted_prong_value = ir_implicit_cast(ira, &instruction->base, this_prong_inst, enum_type);
20441 if (type_is_invalid(this_casted_prong_value->value.type))20489 if (type_is_invalid(this_casted_prong_value->value.type))
20442 return ira->codegen->invalid_instruction;20490 return ira->codegen->invalid_instruction;
2044320491
...@@ -21057,7 +21105,7 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct...@@ -21057,7 +21105,7 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
21057 if (type_is_invalid(value->value.type))21105 if (type_is_invalid(value->value.type))
21058 return ira->codegen->invalid_instruction;21106 return ira->codegen->invalid_instruction;
2105921107
21060 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set);21108 IrInstruction *casted_value = ir_implicit_cast(ira, &instruction->base, value, ira->codegen->builtin_types.entry_global_error_set);
21061 if (type_is_invalid(casted_value->value.type))21109 if (type_is_invalid(casted_value->value.type))
21062 return ira->codegen->invalid_instruction;21110 return ira->codegen->invalid_instruction;
2106321111
...@@ -21165,7 +21213,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -21165,7 +21213,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
21165 field_ptr->value.type->data.pointer.is_volatile,21213 field_ptr->value.type->data.pointer.is_volatile,
21166 PtrLenSingle,21214 PtrLenSingle,
21167 field_ptr_align, 0, 0, false);21215 field_ptr_align, 0, 0, false);
21168 IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type);21216 IrInstruction *casted_field_ptr = ir_implicit_cast(ira, &instruction->base, field_ptr, field_ptr_type);
21169 if (type_is_invalid(casted_field_ptr->value.type))21217 if (type_is_invalid(casted_field_ptr->value.type))
21170 return ira->codegen->invalid_instruction;21218 return ira->codegen->invalid_instruction;
2117121219
...@@ -22309,7 +22357,7 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst...@@ -22309,7 +22357,7 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst
22309{22357{
22310 ConstExprValue *field_val = get_const_field(ira, struct_value, name, field_index);22358 ConstExprValue *field_val = get_const_field(ira, struct_value, name, field_index);
22311 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);22359 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);
22312 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,22360 IrInstruction *casted_field_inst = ir_implicit_cast(ira, source_instr, field_inst,
22313 get_optional_type(ira->codegen, elem_type));22361 get_optional_type(ira->codegen, elem_type));
22314 if (type_is_invalid(casted_field_inst->value.type))22362 if (type_is_invalid(casted_field_inst->value.type))
22315 return ErrorSemanticAnalyzeFail;22363 return ErrorSemanticAnalyzeFail;
...@@ -22456,7 +22504,7 @@ static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionT...@@ -22456,7 +22504,7 @@ static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionT
22456 if (type_is_invalid(type_info_ir->value.type))22504 if (type_is_invalid(type_info_ir->value.type))
22457 return ira->codegen->invalid_instruction;22505 return ira->codegen->invalid_instruction;
2245822506
22459 IrInstruction *casted_ir = ir_implicit_cast(ira, type_info_ir, ir_type_info_get_type(ira, nullptr, nullptr));22507 IrInstruction *casted_ir = ir_implicit_cast(ira, &instruction->base, type_info_ir, ir_type_info_get_type(ira, nullptr, nullptr));
22460 if (type_is_invalid(casted_ir->value.type))22508 if (type_is_invalid(casted_ir->value.type))
22461 return ira->codegen->invalid_instruction;22509 return ira->codegen->invalid_instruction;
2246222510
...@@ -22817,7 +22865,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi...@@ -22817,7 +22865,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2281722865
22818 // TODO let this be volatile22866 // TODO let this be volatile
22819 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);22867 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
22820 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);22868 IrInstruction *casted_ptr = ir_implicit_cast(ira, &instruction->base, ptr, ptr_type);
22821 if (type_is_invalid(casted_ptr->value.type))22869 if (type_is_invalid(casted_ptr->value.type))
22822 return ira->codegen->invalid_instruction;22870 return ira->codegen->invalid_instruction;
2282322871
...@@ -22845,11 +22893,11 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi...@@ -22845,11 +22893,11 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
22845 if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order))22893 if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order))
22846 return ira->codegen->invalid_instruction;22894 return ira->codegen->invalid_instruction;
2284722895
22848 IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type);22896 IrInstruction *casted_cmp_value = ir_implicit_cast(ira, &instruction->base, cmp_value, operand_type);
22849 if (type_is_invalid(casted_cmp_value->value.type))22897 if (type_is_invalid(casted_cmp_value->value.type))
22850 return ira->codegen->invalid_instruction;22898 return ira->codegen->invalid_instruction;
2285122899
22852 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, operand_type);22900 IrInstruction *casted_new_value = ir_implicit_cast(ira, &instruction->base, new_value, operand_type);
22853 if (type_is_invalid(casted_new_value->value.type))22901 if (type_is_invalid(casted_new_value->value.type))
22854 return ira->codegen->invalid_instruction;22902 return ira->codegen->invalid_instruction;
2285522903
...@@ -22943,7 +22991,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct...@@ -22943,7 +22991,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct
22943 }22991 }
2294422992
22945 if (dest_type->id == ZigTypeIdComptimeInt) {22993 if (dest_type->id == ZigTypeIdComptimeInt) {
22946 return ir_implicit_cast(ira, target, dest_type);22994 return ir_implicit_cast(ira, &instruction->base, target, dest_type);
22947 }22995 }
2294822996
22949 if (instr_is_comptime(target)) {22997 if (instr_is_comptime(target)) {
...@@ -23000,7 +23048,7 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct...@@ -23000,7 +23048,7 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct
23000 }23048 }
2300123049
23002 if (instr_is_comptime(target)) {23050 if (instr_is_comptime(target)) {
23003 return ir_implicit_cast(ira, target, dest_type);23051 return ir_implicit_cast(ira, &instruction->base, target, dest_type);
23004 }23052 }
2300523053
23006 if (dest_type->id == ZigTypeIdComptimeInt) {23054 if (dest_type->id == ZigTypeIdComptimeInt) {
...@@ -23128,7 +23176,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -23128,7 +23176,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
23128 src_ptr_align, 0, 0, false);23176 src_ptr_align, 0, 0, false);
23129 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);23177 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
2313023178
23131 IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice);23179 IrInstruction *casted_value = ir_implicit_cast(ira, &instruction->base, target, u8_slice);
23132 if (type_is_invalid(casted_value->value.type))23180 if (type_is_invalid(casted_value->value.type))
23133 return ira->codegen->invalid_instruction;23181 return ira->codegen->invalid_instruction;
2313423182
...@@ -23277,7 +23325,7 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst...@@ -23277,7 +23325,7 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst
23277 return ira->codegen->invalid_instruction;23325 return ira->codegen->invalid_instruction;
2327823326
23279 if (target->value.type->id == ZigTypeIdComptimeInt) {23327 if (target->value.type->id == ZigTypeIdComptimeInt) {
23280 return ir_implicit_cast(ira, target, dest_type);23328 return ir_implicit_cast(ira, &instruction->base, target, dest_type);
23281 }23329 }
2328223330
23283 if (target->value.type->id != ZigTypeIdFloat && target->value.type->id != ZigTypeIdComptimeFloat) {23331 if (target->value.type->id != ZigTypeIdFloat && target->value.type->id != ZigTypeIdComptimeFloat) {
...@@ -23298,7 +23346,7 @@ static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstru...@@ -23298,7 +23346,7 @@ static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstru
23298 if (target->value.type->id == ZigTypeIdErrorSet) {23346 if (target->value.type->id == ZigTypeIdErrorSet) {
23299 casted_target = target;23347 casted_target = target;
23300 } else {23348 } else {
23301 casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);23349 casted_target = ir_implicit_cast(ira, &instruction->base, target, ira->codegen->builtin_types.entry_global_error_set);
23302 if (type_is_invalid(casted_target->value.type))23350 if (type_is_invalid(casted_target->value.type))
23303 return ira->codegen->invalid_instruction;23351 return ira->codegen->invalid_instruction;
23304 }23352 }
...@@ -23311,7 +23359,7 @@ static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstru...@@ -23311,7 +23359,7 @@ static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstru
23311 if (type_is_invalid(target->value.type))23359 if (type_is_invalid(target->value.type))
23312 return ira->codegen->invalid_instruction;23360 return ira->codegen->invalid_instruction;
2331323361
23314 IrInstruction *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type);23362 IrInstruction *casted_target = ir_implicit_cast(ira, &instruction->base, target, ira->codegen->err_tag_type);
23315 if (type_is_invalid(casted_target->value.type))23363 if (type_is_invalid(casted_target->value.type))
23316 return ira->codegen->invalid_instruction;23364 return ira->codegen->invalid_instruction;
2331723365
...@@ -23386,7 +23434,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23386,7 +23434,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
23386 buf_ptr(&mask->value.type->name)));23434 buf_ptr(&mask->value.type->name)));
23387 return ira->codegen->invalid_instruction;23435 return ira->codegen->invalid_instruction;
23388 }23436 }
23389 mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask,23437 mask = ir_implicit_cast(ira, source_instr, mask, get_vector_type(ira->codegen, len_mask,
23390 ira->codegen->builtin_types.entry_i32));23438 ira->codegen->builtin_types.entry_i32));
23391 if (type_is_invalid(mask->value.type))23439 if (type_is_invalid(mask->value.type))
23392 return ira->codegen->invalid_instruction;23440 return ira->codegen->invalid_instruction;
...@@ -23429,7 +23477,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23429,7 +23477,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
23429 len_a = len_b;23477 len_a = len_b;
23430 a = ir_const_undef(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));23478 a = ir_const_undef(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));
23431 } else {23479 } else {
23432 a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));23480 a = ir_implicit_cast(ira, source_instr, a, get_vector_type(ira->codegen, len_a, scalar_type));
23433 if (type_is_invalid(a->value.type))23481 if (type_is_invalid(a->value.type))
23434 return ira->codegen->invalid_instruction;23482 return ira->codegen->invalid_instruction;
23435 }23483 }
...@@ -23438,7 +23486,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -23438,7 +23486,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
23438 len_b = len_a;23486 len_b = len_a;
23439 b = ir_const_undef(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));23487 b = ir_const_undef(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));
23440 } else {23488 } else {
23441 b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));23489 b = ir_implicit_cast(ira, source_instr, b, get_vector_type(ira->codegen, len_b, scalar_type));
23442 if (type_is_invalid(b->value.type))23490 if (type_is_invalid(b->value.type))
23443 return ira->codegen->invalid_instruction;23491 return ira->codegen->invalid_instruction;
23444 }23492 }
...@@ -23614,7 +23662,7 @@ static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruct...@@ -23614,7 +23662,7 @@ static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruct
2361423662
23615 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;23663 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
2361623664
23617 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);23665 IrInstruction *casted_value = ir_implicit_cast(ira, &instruction->base, value, bool_type);
23618 if (type_is_invalid(casted_value->value.type))23666 if (type_is_invalid(casted_value->value.type))
23619 return ira->codegen->invalid_instruction;23667 return ira->codegen->invalid_instruction;
2362023668
...@@ -23663,15 +23711,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -23663,15 +23711,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
23663 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,23711 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
23664 PtrLenUnknown, dest_align, 0, 0, false);23712 PtrLenUnknown, dest_align, 0, 0, false);
2366523713
23666 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);23714 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, &instruction->base, dest_ptr, u8_ptr);
23667 if (type_is_invalid(casted_dest_ptr->value.type))23715 if (type_is_invalid(casted_dest_ptr->value.type))
23668 return ira->codegen->invalid_instruction;23716 return ira->codegen->invalid_instruction;
2366923717
23670 IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8);23718 IrInstruction *casted_byte = ir_implicit_cast(ira, &instruction->base, byte_value, u8);
23671 if (type_is_invalid(casted_byte->value.type))23719 if (type_is_invalid(casted_byte->value.type))
23672 return ira->codegen->invalid_instruction;23720 return ira->codegen->invalid_instruction;
2367323721
23674 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);23722 IrInstruction *casted_count = ir_implicit_cast(ira, &instruction->base, count_value, usize);
23675 if (type_is_invalid(casted_count->value.type))23723 if (type_is_invalid(casted_count->value.type))
23676 return ira->codegen->invalid_instruction;23724 return ira->codegen->invalid_instruction;
2367723725
...@@ -23798,15 +23846,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -23798,15 +23846,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
23798 ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,23846 ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,
23799 PtrLenUnknown, src_align, 0, 0, false);23847 PtrLenUnknown, src_align, 0, 0, false);
2380023848
23801 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);23849 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, &instruction->base, dest_ptr, u8_ptr_mut);
23802 if (type_is_invalid(casted_dest_ptr->value.type))23850 if (type_is_invalid(casted_dest_ptr->value.type))
23803 return ira->codegen->invalid_instruction;23851 return ira->codegen->invalid_instruction;
2380423852
23805 IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const);23853 IrInstruction *casted_src_ptr = ir_implicit_cast(ira, &instruction->base, src_ptr, u8_ptr_const);
23806 if (type_is_invalid(casted_src_ptr->value.type))23854 if (type_is_invalid(casted_src_ptr->value.type))
23807 return ira->codegen->invalid_instruction;23855 return ira->codegen->invalid_instruction;
2380823856
23809 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);23857 IrInstruction *casted_count = ir_implicit_cast(ira, &instruction->base, count_value, usize);
23810 if (type_is_invalid(casted_count->value.type))23858 if (type_is_invalid(casted_count->value.type))
23811 return ira->codegen->invalid_instruction;23859 return ira->codegen->invalid_instruction;
2381223860
...@@ -23946,7 +23994,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -23946,7 +23994,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
23946 return ira->codegen->invalid_instruction;23994 return ira->codegen->invalid_instruction;
2394723995
23948 ZigType *usize = ira->codegen->builtin_types.entry_usize;23996 ZigType *usize = ira->codegen->builtin_types.entry_usize;
23949 IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);23997 IrInstruction *casted_start = ir_implicit_cast(ira, &instruction->base, start, usize);
23950 if (type_is_invalid(casted_start->value.type))23998 if (type_is_invalid(casted_start->value.type))
23951 return ira->codegen->invalid_instruction;23999 return ira->codegen->invalid_instruction;
2395224000
...@@ -23955,7 +24003,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -23955,7 +24003,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
23955 end = instruction->end->child;24003 end = instruction->end->child;
23956 if (type_is_invalid(end->value.type))24004 if (type_is_invalid(end->value.type))
23957 return ira->codegen->invalid_instruction;24005 return ira->codegen->invalid_instruction;
23958 end = ir_implicit_cast(ira, end, usize);24006 end = ir_implicit_cast(ira, &instruction->base, end, usize);
23959 if (type_is_invalid(end->value.type))24007 if (type_is_invalid(end->value.type))
23960 return ira->codegen->invalid_instruction;24008 return ira->codegen->invalid_instruction;
23961 } else {24009 } else {
...@@ -24526,7 +24574,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -24526,7 +24574,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
24526 if (type_is_invalid(op1->value.type))24574 if (type_is_invalid(op1->value.type))
24527 return ira->codegen->invalid_instruction;24575 return ira->codegen->invalid_instruction;
2452824576
24529 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);24577 IrInstruction *casted_op1 = ir_implicit_cast(ira, &instruction->base, op1, dest_type);
24530 if (type_is_invalid(casted_op1->value.type))24578 if (type_is_invalid(casted_op1->value.type))
24531 return ira->codegen->invalid_instruction;24579 return ira->codegen->invalid_instruction;
2453224580
...@@ -24538,9 +24586,9 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -24538,9 +24586,9 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
24538 if (instruction->op == IrOverflowOpShl) {24586 if (instruction->op == IrOverflowOpShl) {
24539 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,24587 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
24540 dest_type->data.integral.bit_count - 1);24588 dest_type->data.integral.bit_count - 1);
24541 casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type);24589 casted_op2 = ir_implicit_cast(ira, &instruction->base, op2, shift_amt_type);
24542 } else {24590 } else {
24543 casted_op2 = ir_implicit_cast(ira, op2, dest_type);24591 casted_op2 = ir_implicit_cast(ira, &instruction->base, op2, dest_type);
24544 }24592 }
24545 if (type_is_invalid(casted_op2->value.type))24593 if (type_is_invalid(casted_op2->value.type))
24546 return ira->codegen->invalid_instruction;24594 return ira->codegen->invalid_instruction;
...@@ -24562,7 +24610,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -24562,7 +24610,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
24562 expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);24610 expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);
24563 }24611 }
2456424612
24565 IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type);24613 IrInstruction *casted_result_ptr = ir_implicit_cast(ira, &instruction->base, result_ptr, expected_ptr_type);
24566 if (type_is_invalid(casted_result_ptr->value.type))24614 if (type_is_invalid(casted_result_ptr->value.type))
24567 return ira->codegen->invalid_instruction;24615 return ira->codegen->invalid_instruction;
2456824616
...@@ -24672,7 +24720,7 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi...@@ -24672,7 +24720,7 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
24672 if (type_is_invalid(op1->value.type))24720 if (type_is_invalid(op1->value.type))
24673 return ira->codegen->invalid_instruction;24721 return ira->codegen->invalid_instruction;
2467424722
24675 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, expr_type);24723 IrInstruction *casted_op1 = ir_implicit_cast(ira, &instruction->base, op1, expr_type);
24676 if (type_is_invalid(casted_op1->value.type))24724 if (type_is_invalid(casted_op1->value.type))
24677 return ira->codegen->invalid_instruction;24725 return ira->codegen->invalid_instruction;
2467824726
...@@ -24680,7 +24728,7 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi...@@ -24680,7 +24728,7 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
24680 if (type_is_invalid(op2->value.type))24728 if (type_is_invalid(op2->value.type))
24681 return ira->codegen->invalid_instruction;24729 return ira->codegen->invalid_instruction;
2468224730
24683 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, expr_type);24731 IrInstruction *casted_op2 = ir_implicit_cast(ira, &instruction->base, op2, expr_type);
24684 if (type_is_invalid(casted_op2->value.type))24732 if (type_is_invalid(casted_op2->value.type))
24685 return ira->codegen->invalid_instruction;24733 return ira->codegen->invalid_instruction;
2468624734
...@@ -24688,7 +24736,7 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi...@@ -24688,7 +24736,7 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
24688 if (type_is_invalid(op3->value.type))24736 if (type_is_invalid(op3->value.type))
24689 return ira->codegen->invalid_instruction;24737 return ira->codegen->invalid_instruction;
2469024738
24691 IrInstruction *casted_op3 = ir_implicit_cast(ira, op3, expr_type);24739 IrInstruction *casted_op3 = ir_implicit_cast(ira, &instruction->base, op3, expr_type);
24692 if (type_is_invalid(casted_op3->value.type))24740 if (type_is_invalid(casted_op3->value.type))
24693 return ira->codegen->invalid_instruction;24741 return ira->codegen->invalid_instruction;
2469424742
...@@ -25060,14 +25108,14 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -25060,14 +25108,14 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
25060 IrInstruction *start_value_uncasted = range->start->child;25108 IrInstruction *start_value_uncasted = range->start->child;
25061 if (type_is_invalid(start_value_uncasted->value.type))25109 if (type_is_invalid(start_value_uncasted->value.type))
25062 return ira->codegen->invalid_instruction;25110 return ira->codegen->invalid_instruction;
25063 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);25111 IrInstruction *start_value = ir_implicit_cast(ira, &instruction->base, start_value_uncasted, switch_type);
25064 if (type_is_invalid(start_value->value.type))25112 if (type_is_invalid(start_value->value.type))
25065 return ira->codegen->invalid_instruction;25113 return ira->codegen->invalid_instruction;
2506625114
25067 IrInstruction *end_value_uncasted = range->end->child;25115 IrInstruction *end_value_uncasted = range->end->child;
25068 if (type_is_invalid(end_value_uncasted->value.type))25116 if (type_is_invalid(end_value_uncasted->value.type))
25069 return ira->codegen->invalid_instruction;25117 return ira->codegen->invalid_instruction;
25070 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);25118 IrInstruction *end_value = ir_implicit_cast(ira, &instruction->base, end_value_uncasted, switch_type);
25071 if (type_is_invalid(end_value->value.type))25119 if (type_is_invalid(end_value->value.type))
25072 return ira->codegen->invalid_instruction;25120 return ira->codegen->invalid_instruction;
2507325121
...@@ -25124,14 +25172,14 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -25124,14 +25172,14 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
25124 IrInstruction *start_value_uncasted = range->start->child;25172 IrInstruction *start_value_uncasted = range->start->child;
25125 if (type_is_invalid(start_value_uncasted->value.type))25173 if (type_is_invalid(start_value_uncasted->value.type))
25126 return ira->codegen->invalid_instruction;25174 return ira->codegen->invalid_instruction;
25127 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);25175 IrInstruction *start_value = ir_implicit_cast(ira, &instruction->base, start_value_uncasted, switch_type);
25128 if (type_is_invalid(start_value->value.type))25176 if (type_is_invalid(start_value->value.type))
25129 return ira->codegen->invalid_instruction;25177 return ira->codegen->invalid_instruction;
2513025178
25131 IrInstruction *end_value_uncasted = range->end->child;25179 IrInstruction *end_value_uncasted = range->end->child;
25132 if (type_is_invalid(end_value_uncasted->value.type))25180 if (type_is_invalid(end_value_uncasted->value.type))
25133 return ira->codegen->invalid_instruction;25181 return ira->codegen->invalid_instruction;
25134 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);25182 IrInstruction *end_value = ir_implicit_cast(ira, &instruction->base, end_value_uncasted, switch_type);
25135 if (type_is_invalid(end_value->value.type))25183 if (type_is_invalid(end_value->value.type))
25136 return ira->codegen->invalid_instruction;25184 return ira->codegen->invalid_instruction;
2513725185
...@@ -25182,14 +25230,14 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -25182,14 +25230,14 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
25182 IrInstruction *start_value = range->start->child;25230 IrInstruction *start_value = range->start->child;
25183 if (type_is_invalid(start_value->value.type))25231 if (type_is_invalid(start_value->value.type))
25184 return ira->codegen->invalid_instruction;25232 return ira->codegen->invalid_instruction;
25185 IrInstruction *casted_start_value = ir_implicit_cast(ira, start_value, switch_type);25233 IrInstruction *casted_start_value = ir_implicit_cast(ira, &instruction->base, start_value, switch_type);
25186 if (type_is_invalid(casted_start_value->value.type))25234 if (type_is_invalid(casted_start_value->value.type))
25187 return ira->codegen->invalid_instruction;25235 return ira->codegen->invalid_instruction;
2518825236
25189 IrInstruction *end_value = range->end->child;25237 IrInstruction *end_value = range->end->child;
25190 if (type_is_invalid(end_value->value.type))25238 if (type_is_invalid(end_value->value.type))
25191 return ira->codegen->invalid_instruction;25239 return ira->codegen->invalid_instruction;
25192 IrInstruction *casted_end_value = ir_implicit_cast(ira, end_value, switch_type);25240 IrInstruction *casted_end_value = ir_implicit_cast(ira, &instruction->base, end_value, switch_type);
25193 if (type_is_invalid(casted_end_value->value.type))25241 if (type_is_invalid(casted_end_value->value.type))
25194 return ira->codegen->invalid_instruction;25242 return ira->codegen->invalid_instruction;
2519525243
...@@ -25229,7 +25277,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -25229,7 +25277,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2522925277
25230 IrInstruction *value = range->start->child;25278 IrInstruction *value = range->start->child;
2523125279
25232 IrInstruction *casted_value = ir_implicit_cast(ira, value, switch_type);25280 IrInstruction *casted_value = ir_implicit_cast(ira, &instruction->base, value, switch_type);
25233 if (type_is_invalid(casted_value->value.type))25281 if (type_is_invalid(casted_value->value.type))
25234 return ira->codegen->invalid_instruction;25282 return ira->codegen->invalid_instruction;
2523525283
...@@ -25290,7 +25338,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction...@@ -25290,7 +25338,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction
25290 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,25338 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
25291 true, false, PtrLenUnknown, 0, 0, 0, false);25339 true, false, PtrLenUnknown, 0, 0, 0, false);
25292 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);25340 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
25293 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);25341 IrInstruction *casted_msg = ir_implicit_cast(ira, &instruction->base, msg, str_type);
25294 if (type_is_invalid(casted_msg->value.type))25342 if (type_is_invalid(casted_msg->value.type))
25295 return ir_unreach_error(ira);25343 return ir_unreach_error(ira);
2529625344
...@@ -25900,7 +25948,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc...@@ -25900,7 +25948,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
25900 ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr);25948 ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr);
25901 ir_assert(type_has_bits(ptr_type), source_instr);25949 ir_assert(type_has_bits(ptr_type), source_instr);
2590225950
25903 IrInstruction *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);25951 IrInstruction *casted_int = ir_implicit_cast(ira, source_instr, target, ira->codegen->builtin_types.entry_usize);
25904 if (type_is_invalid(casted_int->value.type))25952 if (type_is_invalid(casted_int->value.type))
25905 return ira->codegen->invalid_instruction;25953 return ira->codegen->invalid_instruction;
2590625954
...@@ -26259,7 +26307,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru...@@ -26259,7 +26307,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru
2625926307
26260 // TODO let this be volatile26308 // TODO let this be volatile
26261 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);26309 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
26262 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);26310 IrInstruction *casted_ptr = ir_implicit_cast(ira, &instruction->base, ptr_inst, ptr_type);
26263 if (type_is_invalid(casted_ptr->value.type))26311 if (type_is_invalid(casted_ptr->value.type))
26264 return ira->codegen->invalid_instruction;26312 return ira->codegen->invalid_instruction;
2626526313
...@@ -26282,7 +26330,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru...@@ -26282,7 +26330,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru
26282 if (type_is_invalid(operand->value.type))26330 if (type_is_invalid(operand->value.type))
26283 return ira->codegen->invalid_instruction;26331 return ira->codegen->invalid_instruction;
2628426332
26285 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, operand_type);26333 IrInstruction *casted_operand = ir_implicit_cast(ira, &instruction->base, operand, operand_type);
26286 if (type_is_invalid(casted_operand->value.type))26334 if (type_is_invalid(casted_operand->value.type))
26287 return ira->codegen->invalid_instruction;26335 return ira->codegen->invalid_instruction;
2628826336
...@@ -26321,7 +26369,7 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr...@@ -26321,7 +26369,7 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr
26321 return ira->codegen->invalid_instruction;26369 return ira->codegen->invalid_instruction;
2632226370
26323 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);26371 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);
26324 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);26372 IrInstruction *casted_ptr = ir_implicit_cast(ira, &instruction->base, ptr_inst, ptr_type);
26325 if (type_is_invalid(casted_ptr->value.type))26373 if (type_is_invalid(casted_ptr->value.type))
26326 return ira->codegen->invalid_instruction;26374 return ira->codegen->invalid_instruction;
2632726375
...@@ -26362,7 +26410,7 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst...@@ -26362,7 +26410,7 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst
26362 return ira->codegen->invalid_instruction;26410 return ira->codegen->invalid_instruction;
2636326411
26364 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);26412 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
26365 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);26413 IrInstruction *casted_ptr = ir_implicit_cast(ira, &instruction->base, ptr_inst, ptr_type);
26366 if (type_is_invalid(casted_ptr->value.type))26414 if (type_is_invalid(casted_ptr->value.type))
26367 return ira->codegen->invalid_instruction;26415 return ira->codegen->invalid_instruction;
2636826416
...@@ -26370,7 +26418,7 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst...@@ -26370,7 +26418,7 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst
26370 if (type_is_invalid(value->value.type))26418 if (type_is_invalid(value->value.type))
26371 return ira->codegen->invalid_instruction;26419 return ira->codegen->invalid_instruction;
2637226420
26373 IrInstruction *casted_value = ir_implicit_cast(ira, value, operand_type);26421 IrInstruction *casted_value = ir_implicit_cast(ira, &instruction->base, value, operand_type);
26374 if (type_is_invalid(casted_value->value.type))26422 if (type_is_invalid(casted_value->value.type))
26375 return ira->codegen->invalid_instruction;26423 return ira->codegen->invalid_instruction;
2637626424
...@@ -26609,7 +26657,7 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct...@@ -26609,7 +26657,7 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
26609 if (type_is_invalid(op1->value.type))26657 if (type_is_invalid(op1->value.type))
26610 return ira->codegen->invalid_instruction;26658 return ira->codegen->invalid_instruction;
2661126659
26612 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, float_type);26660 IrInstruction *casted_op1 = ir_implicit_cast(ira, &instruction->base, op1, float_type);
26613 if (type_is_invalid(casted_op1->value.type))26661 if (type_is_invalid(casted_op1->value.type))
26614 return ira->codegen->invalid_instruction;26662 return ira->codegen->invalid_instruction;
2661526663
...@@ -26685,7 +26733,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -26685,7 +26733,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
26685 bool is_vector = (vector_len != UINT32_MAX);26733 bool is_vector = (vector_len != UINT32_MAX);
26686 ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type;26734 ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type;
2668726735
26688 IrInstruction *op = ir_implicit_cast(ira, uncasted_op, op_type);26736 IrInstruction *op = ir_implicit_cast(ira, &instruction->base, uncasted_op, op_type);
26689 if (type_is_invalid(op->value.type))26737 if (type_is_invalid(op->value.type))
26690 return ira->codegen->invalid_instruction;26738 return ira->codegen->invalid_instruction;
2669126739
...@@ -26750,7 +26798,7 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr...@@ -26750,7 +26798,7 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
26750 if (type_is_invalid(int_type))26798 if (type_is_invalid(int_type))
26751 return ira->codegen->invalid_instruction;26799 return ira->codegen->invalid_instruction;
2675226800
26753 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);26801 IrInstruction *op = ir_implicit_cast(ira, &instruction->base, instruction->op->child, int_type);
26754 if (type_is_invalid(op->value.type))26802 if (type_is_invalid(op->value.type))
26755 return ira->codegen->invalid_instruction;26803 return ira->codegen->invalid_instruction;
2675626804
...@@ -26831,7 +26879,7 @@ static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstr...@@ -26831,7 +26879,7 @@ static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstr
26831 if (type_is_invalid(target->value.type))26879 if (type_is_invalid(target->value.type))
26832 return ira->codegen->invalid_instruction;26880 return ira->codegen->invalid_instruction;
2683326881
26834 IrInstruction *casted_target = ir_implicit_cast(ira, target, tag_type);26882 IrInstruction *casted_target = ir_implicit_cast(ira, &instruction->base, target, tag_type);
26835 if (type_is_invalid(casted_target->value.type))26883 if (type_is_invalid(casted_target->value.type))
26836 return ira->codegen->invalid_instruction;26884 return ira->codegen->invalid_instruction;
2683726885
...@@ -26950,7 +26998,7 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns...@@ -26950,7 +26998,7 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns
26950 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);26998 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);
26951 if (type_is_invalid(dest_type))26999 if (type_is_invalid(dest_type))
26952 return ira->codegen->invalid_instruction;27000 return ira->codegen->invalid_instruction;
26953 return ir_implicit_cast_with_result(ira, &instruction->base, operand, dest_type, nullptr);27001 return ir_implicit_cast(ira, &instruction->base, operand, dest_type);
26954}27002}
2695527003
26956static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) {27004static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) {
...@@ -27063,7 +27111,7 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct...@@ -27063,7 +27111,7 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct
27063 }27111 }
2706427112
27065 ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type);27113 ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type);
27066 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);27114 IrInstruction *casted_frame = ir_implicit_cast(ira, source_instr, frame, any_frame_type);
27067 if (type_is_invalid(casted_frame->value.type))27115 if (type_is_invalid(casted_frame->value.type))
27068 return ira->codegen->invalid_instruction;27116 return ira->codegen->invalid_instruction;
2706927117
...@@ -27127,7 +27175,7 @@ static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructio...@@ -27127,7 +27175,7 @@ static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructio
27127 }27175 }
2712827176
27129 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);27177 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);
27130 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);27178 IrInstruction *casted_frame = ir_implicit_cast(ira, &instruction->base, frame, any_frame_type);
27131 if (type_is_invalid(casted_frame->value.type))27179 if (type_is_invalid(casted_frame->value.type))
27132 return ira->codegen->invalid_instruction;27180 return ira->codegen->invalid_instruction;
2713327181
...@@ -27979,7 +28027,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -27979,7 +28027,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
27979 if (lazy_slice_type->sentinel != nullptr) {28027 if (lazy_slice_type->sentinel != nullptr) {
27980 if (type_is_invalid(lazy_slice_type->sentinel->value.type))28028 if (type_is_invalid(lazy_slice_type->sentinel->value.type))
27981 return ErrorSemanticAnalyzeFail;28029 return ErrorSemanticAnalyzeFail;
27982 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type);28030 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, lazy_slice_type->sentinel, elem_type);
27983 if (type_is_invalid(sentinel->value.type))28031 if (type_is_invalid(sentinel->value.type))
27984 return ErrorSemanticAnalyzeFail;28032 return ErrorSemanticAnalyzeFail;
27985 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);28033 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
...@@ -28057,7 +28105,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {...@@ -28057,7 +28105,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
28057 if (lazy_ptr_type->sentinel != nullptr) {28105 if (lazy_ptr_type->sentinel != nullptr) {
28058 if (type_is_invalid(lazy_ptr_type->sentinel->value.type))28106 if (type_is_invalid(lazy_ptr_type->sentinel->value.type))
28059 return ErrorSemanticAnalyzeFail;28107 return ErrorSemanticAnalyzeFail;
28060 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type);28108 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, lazy_ptr_type->sentinel, elem_type);
28061 if (type_is_invalid(sentinel->value.type))28109 if (type_is_invalid(sentinel->value.type))
28062 return ErrorSemanticAnalyzeFail;28110 return ErrorSemanticAnalyzeFail;
28063 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);28111 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
test/stage1/behavior/cast.zig+53
...@@ -621,3 +621,56 @@ test "peer resolution of string literals" {...@@ -621,3 +621,56 @@ test "peer resolution of string literals" {
621 S.doTheTest(.b);621 S.doTheTest(.b);
622 comptime S.doTheTest(.b);622 comptime S.doTheTest(.b);
623}623}
624
625test "type coercion related to sentinel-termination" {
626 const S = struct {
627 fn doTheTest() void {
628 // [:x]T to []T
629 {
630 var array = [4:0]i32{1,2,3,4};
631 var slice: [:0]i32 = &array;
632 var dest: []i32 = slice;
633 expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));
634 }
635
636 // [*:x]T to [*]T
637 {
638 var array = [4:99]i32{1,2,3,4};
639 var dest: [*]i32 = &array;
640 expect(dest[0] == 1);
641 expect(dest[1] == 2);
642 expect(dest[2] == 3);
643 expect(dest[3] == 4);
644 expect(dest[4] == 99);
645 }
646
647 // [N:x]T to [N]T
648 {
649 var array = [4:0]i32{1,2,3,4};
650 var dest: [4]i32 = array;
651 expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));
652 }
653
654 // *[N:x]T to *[N]T
655 {
656 var array = [4:0]i32{1,2,3,4};
657 var dest: *[4]i32 = &array;
658 expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));
659 }
660
661 // [:x]T to [*:x]T
662 {
663 var array = [4:0]i32{1,2,3,4};
664 var slice: [:0]i32 = &array;
665 var dest: [*:0]i32 = slice;
666 expect(dest[0] == 1);
667 expect(dest[1] == 2);
668 expect(dest[2] == 3);
669 expect(dest[3] == 4);
670 expect(dest[4] == 0);
671 }
672 }
673 };
674 S.doTheTest();
675 comptime S.doTheTest();
676}