| ... | @@ -15955,38 +15955,46 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, | ... | @@ -15955,38 +15955,46 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 15955 | anon_type->data.structure.special == StructSpecialInferredTuple; | 15955 | anon_type->data.structure.special == StructSpecialInferredTuple; |
| 15956 | const uint32_t field_count = anon_type->data.structure.src_field_count; | 15956 | const uint32_t field_count = anon_type->data.structure.src_field_count; |
| 15957 | | 15957 | |
| 15958 | if (wanted_type->id == ZigTypeIdPointer) { | 15958 | if (wanted_type->id == ZigTypeIdPointer && |
| | 15959 | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile)) |
| | 15960 | { |
| 15959 | ZigType *wanted_child = wanted_type->data.pointer.child_type; | 15961 | ZigType *wanted_child = wanted_type->data.pointer.child_type; |
| | 15962 | bool const_ok = (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const); |
| 15960 | if (wanted_child->id == ZigTypeIdArray && (is_array_init || field_count == 0) && | 15963 | if (wanted_child->id == ZigTypeIdArray && (is_array_init || field_count == 0) && |
| 15961 | wanted_child->data.array.len == field_count) | 15964 | wanted_child->data.array.len == field_count && (const_ok || field_count == 0)) |
| 15962 | { | 15965 | { |
| 15963 | IrInstGen *res = ir_analyze_struct_literal_to_array(ira, source_instr, value, anon_type, wanted_child); | 15966 | IrInstGen *res = ir_analyze_struct_literal_to_array(ira, source_instr, value, anon_type, wanted_child); |
| 15964 | if (res->value->type->id == ZigTypeIdPointer) | 15967 | if (res->value->type->id == ZigTypeIdPointer) |
| 15965 | return res; | 15968 | return res; |
| 15966 | return ir_get_ref(ira, source_instr, res, wanted_type->data.pointer.is_const, wanted_type->data.pointer.is_volatile); | 15969 | return ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile); |
| 15967 | } else if (wanted_child->id == ZigTypeIdStruct && !is_slice(wanted_type) && | 15970 | } else if (wanted_child->id == ZigTypeIdStruct && !is_slice(wanted_type) && |
| 15968 | (!is_array_init || field_count == 0)) | 15971 | (!is_array_init || field_count == 0) && const_ok) |
| 15969 | { | 15972 | { |
| 15970 | IrInstGen *res = ir_analyze_struct_literal_to_struct(ira, source_instr, value, anon_type, wanted_child); | 15973 | IrInstGen *res = ir_analyze_struct_literal_to_struct(ira, source_instr, value, anon_type, wanted_child); |
| 15971 | if (res->value->type->id == ZigTypeIdPointer) | 15974 | if (res->value->type->id == ZigTypeIdPointer) |
| 15972 | return res; | 15975 | return res; |
| 15973 | return ir_get_ref(ira, source_instr, res, wanted_type->data.pointer.is_const, wanted_type->data.pointer.is_volatile); | 15976 | return ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile); |
| 15974 | } else if (wanted_child->id == ZigTypeIdUnion && !is_array_init && field_count == 1) { | 15977 | } else if (wanted_child->id == ZigTypeIdUnion && !is_array_init && field_count == 1 && const_ok) { |
| 15975 | IrInstGen *res = ir_analyze_struct_literal_to_union(ira, source_instr, value, anon_type, wanted_child); | 15978 | IrInstGen *res = ir_analyze_struct_literal_to_union(ira, source_instr, value, anon_type, wanted_child); |
| 15976 | if (res->value->type->id == ZigTypeIdPointer) | 15979 | if (res->value->type->id == ZigTypeIdPointer) |
| 15977 | return res; | 15980 | return res; |
| 15978 | return ir_get_ref(ira, source_instr, res, wanted_type->data.pointer.is_const, wanted_type->data.pointer.is_volatile); | 15981 | return ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile); |
| 15979 | } | 15982 | } |
| 15980 | } else if (is_slice(wanted_type) && (is_array_init || field_count == 0)) { | 15983 | } else if (is_slice(wanted_type) && (is_array_init || field_count == 0)) { |
| 15981 | ZigType *slice_child_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.child_type; | 15984 | ZigType *slice_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 15982 | ZigType *slice_array_type = get_array_type(ira->codegen, slice_child_type, field_count, nullptr); | 15985 | if ((!actual_type->data.pointer.is_const || slice_type->data.pointer.is_const || field_count == 0) && |
| 15983 | IrInstGen *res = ir_analyze_struct_literal_to_array(ira, source_instr, value, anon_type, slice_array_type); | 15986 | (!actual_type->data.pointer.is_volatile || slice_type->data.pointer.is_volatile)) |
| 15984 | if (type_is_invalid(res->value->type)) | 15987 | { |
| 15985 | return ira->codegen->invalid_inst_gen; | 15988 | ZigType *slice_child_type = slice_type->data.pointer.child_type; |
| 15986 | if (res->value->type->id != ZigTypeIdPointer) | 15989 | ZigType *slice_array_type = get_array_type(ira->codegen, slice_child_type, field_count, nullptr); |
| 15987 | res = ir_get_ref(ira, source_instr, res, wanted_type->data.pointer.is_const, wanted_type->data.pointer.is_volatile); | 15990 | IrInstGen *res = ir_analyze_struct_literal_to_array(ira, source_instr, value, anon_type, slice_array_type); |
| | 15991 | if (type_is_invalid(res->value->type)) |
| | 15992 | return ira->codegen->invalid_inst_gen; |
| | 15993 | if (res->value->type->id != ZigTypeIdPointer) |
| | 15994 | res = ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile); |
| 15988 | | 15995 | |
| 15989 | return ir_resolve_ptr_of_array_to_slice(ira, source_instr, res, wanted_type, nullptr); | 15996 | return ir_resolve_ptr_of_array_to_slice(ira, source_instr, res, wanted_type, nullptr); |
| | 15997 | } |
| 15990 | } | 15998 | } |
| 15991 | } | 15999 | } |
| 15992 | | 16000 | |