| ... | @@ -20007,29 +20007,24 @@ static Stage1AirInst *ir_analyze_instruction_truncate(IrAnalyze *ira, Stage1ZirI | ... | @@ -20007,29 +20007,24 @@ static Stage1AirInst *ir_analyze_instruction_truncate(IrAnalyze *ira, Stage1ZirI |
| 20007 | return ir_build_truncate_gen(ira, instruction->base.scope, instruction->base.source_node, dest_type, target); | 20007 | return ir_build_truncate_gen(ira, instruction->base.scope, instruction->base.source_node, dest_type, target); |
| 20008 | } | 20008 | } |
| 20009 | | 20009 | |
| 20010 | static Stage1AirInst *ir_analyze_instruction_int_cast(IrAnalyze *ira, Stage1ZirInstIntCast *instruction) { | 20010 | static Stage1AirInst *ir_analyze_int_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 20011 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); | 20011 | ZigType *dest_type, AstNode *dest_type_src_node, |
| 20012 | if (type_is_invalid(dest_type)) | 20012 | Stage1AirInst *target, AstNode *target_src_node) |
| 20013 | return ira->codegen->invalid_inst_gen; | 20013 | { |
| 20014 | | | |
| 20015 | ZigType *scalar_dest_type = (dest_type->id == ZigTypeIdVector) ? | 20014 | ZigType *scalar_dest_type = (dest_type->id == ZigTypeIdVector) ? |
| 20016 | dest_type->data.vector.elem_type : dest_type; | 20015 | dest_type->data.vector.elem_type : dest_type; |
| 20017 | | 20016 | |
| 20018 | if (scalar_dest_type->id != ZigTypeIdInt && scalar_dest_type->id != ZigTypeIdComptimeInt) { | 20017 | if (scalar_dest_type->id != ZigTypeIdInt && scalar_dest_type->id != ZigTypeIdComptimeInt) { |
| 20019 | ir_add_error_node(ira, instruction->dest_type->source_node, | 20018 | ir_add_error_node(ira, dest_type_src_node, |
| 20020 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&scalar_dest_type->name))); | 20019 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&scalar_dest_type->name))); |
| 20021 | return ira->codegen->invalid_inst_gen; | 20020 | return ira->codegen->invalid_inst_gen; |
| 20022 | } | 20021 | } |
| 20023 | | 20022 | |
| 20024 | Stage1AirInst *target = instruction->target->child; | | |
| 20025 | if (type_is_invalid(target->value->type)) | | |
| 20026 | return ira->codegen->invalid_inst_gen; | | |
| 20027 | | | |
| 20028 | ZigType *scalar_target_type = (target->value->type->id == ZigTypeIdVector) ? | 20023 | ZigType *scalar_target_type = (target->value->type->id == ZigTypeIdVector) ? |
| 20029 | target->value->type->data.vector.elem_type : target->value->type; | 20024 | target->value->type->data.vector.elem_type : target->value->type; |
| 20030 | | 20025 | |
| 20031 | if (scalar_target_type->id != ZigTypeIdInt && scalar_target_type->id != ZigTypeIdComptimeInt) { | 20026 | if (scalar_target_type->id != ZigTypeIdInt && scalar_target_type->id != ZigTypeIdComptimeInt) { |
| 20032 | ir_add_error_node(ira, instruction->target->source_node, buf_sprintf("expected integer type, found '%s'", | 20027 | ir_add_error_node(ira, target_src_node, buf_sprintf("expected integer type, found '%s'", |
| 20033 | buf_ptr(&scalar_target_type->name))); | 20028 | buf_ptr(&scalar_target_type->name))); |
| 20034 | return ira->codegen->invalid_inst_gen; | 20029 | return ira->codegen->invalid_inst_gen; |
| 20035 | } | 20030 | } |
| ... | @@ -20039,10 +20034,24 @@ static Stage1AirInst *ir_analyze_instruction_int_cast(IrAnalyze *ira, Stage1ZirI | ... | @@ -20039,10 +20034,24 @@ static Stage1AirInst *ir_analyze_instruction_int_cast(IrAnalyze *ira, Stage1ZirI |
| 20039 | if (val == nullptr) | 20034 | if (val == nullptr) |
| 20040 | return ira->codegen->invalid_inst_gen; | 20035 | return ira->codegen->invalid_inst_gen; |
| 20041 | | 20036 | |
| 20042 | return ir_implicit_cast2(ira, instruction->target->scope, instruction->target->source_node, target, dest_type); | 20037 | return ir_implicit_cast2(ira, scope, target_src_node, target, dest_type); |
| 20043 | } | 20038 | } |
| 20044 | | 20039 | |
| 20045 | return ir_analyze_widen_or_shorten(ira, instruction->base.scope, instruction->base.source_node, target, dest_type); | 20040 | return ir_analyze_widen_or_shorten(ira, scope, source_node, target, dest_type); |
| | 20041 | } |
| | 20042 | |
| | 20043 | static Stage1AirInst *ir_analyze_instruction_int_cast(IrAnalyze *ira, Stage1ZirInstIntCast *instruction) { |
| | 20044 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| | 20045 | if (type_is_invalid(dest_type)) |
| | 20046 | return ira->codegen->invalid_inst_gen; |
| | 20047 | |
| | 20048 | Stage1AirInst *target = instruction->target->child; |
| | 20049 | if (type_is_invalid(target->value->type)) |
| | 20050 | return ira->codegen->invalid_inst_gen; |
| | 20051 | |
| | 20052 | return ir_analyze_int_cast(ira, instruction->base.scope, instruction->base.source_node, |
| | 20053 | dest_type, instruction->dest_type->source_node, |
| | 20054 | target, instruction->target->source_node); |
| 20046 | } | 20055 | } |
| 20047 | | 20056 | |
| 20048 | static Stage1AirInst *ir_analyze_instruction_float_cast(IrAnalyze *ira, Stage1ZirInstFloatCast *instruction) { | 20057 | static Stage1AirInst *ir_analyze_instruction_float_cast(IrAnalyze *ira, Stage1ZirInstFloatCast *instruction) { |
| ... | @@ -24282,7 +24291,9 @@ static Stage1AirInst *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, Stage1Z | ... | @@ -24282,7 +24291,9 @@ static Stage1AirInst *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, Stage1Z |
| 24282 | if (type_is_invalid(target->value->type)) | 24291 | if (type_is_invalid(target->value->type)) |
| 24283 | return ira->codegen->invalid_inst_gen; | 24292 | return ira->codegen->invalid_inst_gen; |
| 24284 | | 24293 | |
| 24285 | Stage1AirInst *casted_target = ir_implicit_cast(ira, target, tag_type); | 24294 | Stage1AirInst *casted_target = ir_analyze_int_cast(ira, instruction->base.scope, |
| | 24295 | instruction->base.source_node, tag_type, instruction->dest_type->source_node, |
| | 24296 | target, instruction->target->source_node); |
| 24286 | if (type_is_invalid(casted_target->value->type)) | 24297 | if (type_is_invalid(casted_target->value->type)) |
| 24287 | return ira->codegen->invalid_inst_gen; | 24298 | return ira->codegen->invalid_inst_gen; |
| 24288 | | 24299 | |