| ... | @@ -25957,16 +25957,10 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa | ... | @@ -25957,16 +25957,10 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa |
| 25957 | return ira->codegen->invalid_inst_gen; | 25957 | return ira->codegen->invalid_inst_gen; |
| 25958 | } | 25958 | } |
| 25959 | | 25959 | |
| 25960 | if (instr_is_comptime(target)) { | 25960 | if (instr_is_comptime(target) || dest_type->id == ZigTypeIdComptimeInt) { |
| 25961 | return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type); | 25961 | return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type); |
| 25962 | } | 25962 | } |
| 25963 | | 25963 | |
| 25964 | if (dest_type->id == ZigTypeIdComptimeInt) { | | |
| 25965 | ir_add_error(ira, &instruction->target->base, buf_sprintf("attempt to cast runtime value to '%s'", | | |
| 25966 | buf_ptr(&dest_type->name))); | | |
| 25967 | return ira->codegen->invalid_inst_gen; | | |
| 25968 | } | | |
| 25969 | | | |
| 25970 | return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type); | 25964 | return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type); |
| 25971 | } | 25965 | } |
| 25972 | | 25966 | |
| ... | @@ -25975,7 +25969,7 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo | ... | @@ -25975,7 +25969,7 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo |
| 25975 | if (type_is_invalid(dest_type)) | 25969 | if (type_is_invalid(dest_type)) |
| 25976 | return ira->codegen->invalid_inst_gen; | 25970 | return ira->codegen->invalid_inst_gen; |
| 25977 | | 25971 | |
| 25978 | if (dest_type->id != ZigTypeIdFloat) { | 25972 | if (dest_type->id != ZigTypeIdFloat && dest_type->id != ZigTypeIdComptimeFloat) { |
| 25979 | ir_add_error(ira, &instruction->dest_type->base, | 25973 | ir_add_error(ira, &instruction->dest_type->base, |
| 25980 | buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name))); | 25974 | buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name))); |
| 25981 | return ira->codegen->invalid_inst_gen; | 25975 | return ira->codegen->invalid_inst_gen; |
| ... | @@ -26001,6 +25995,10 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo | ... | @@ -26001,6 +25995,10 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo |
| 26001 | } | 25995 | } |
| 26002 | } | 25996 | } |
| 26003 | | 25997 | |
| | 25998 | if (instr_is_comptime(target) || dest_type->id == ZigTypeIdComptimeFloat) { |
| | 25999 | return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type); |
| | 26000 | } |
| | 26001 | |
| 26004 | if (target->value->type->id != ZigTypeIdFloat) { | 26002 | if (target->value->type->id != ZigTypeIdFloat) { |
| 26005 | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected float type, found '%s'", | 26003 | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected float type, found '%s'", |
| 26006 | buf_ptr(&target->value->type->name))); | 26004 | buf_ptr(&target->value->type->name))); |
| ... | @@ -26064,6 +26062,12 @@ static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcI | ... | @@ -26064,6 +26062,12 @@ static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcI |
| 26064 | if (type_is_invalid(dest_type)) | 26062 | if (type_is_invalid(dest_type)) |
| 26065 | return ira->codegen->invalid_inst_gen; | 26063 | return ira->codegen->invalid_inst_gen; |
| 26066 | | 26064 | |
| | 26065 | if (dest_type->id != ZigTypeIdFloat && dest_type->id != ZigTypeIdComptimeFloat) { |
| | 26066 | ir_add_error(ira, &instruction->dest_type->base, |
| | 26067 | buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name))); |
| | 26068 | return ira->codegen->invalid_inst_gen; |
| | 26069 | } |
| | 26070 | |
| 26067 | IrInstGen *target = instruction->target->child; | 26071 | IrInstGen *target = instruction->target->child; |
| 26068 | if (type_is_invalid(target->value->type)) | 26072 | if (type_is_invalid(target->value->type)) |
| 26069 | return ira->codegen->invalid_inst_gen; | 26073 | return ira->codegen->invalid_inst_gen; |
| ... | @@ -26077,33 +26081,31 @@ static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcI | ... | @@ -26077,33 +26081,31 @@ static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcI |
| 26077 | return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpIntToFloat); | 26081 | return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpIntToFloat); |
| 26078 | } | 26082 | } |
| 26079 | | 26083 | |
| 26080 | static IrInstGen *ir_analyze_float_to_int(IrAnalyze *ira, IrInst* source_instr, | 26084 | static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcFloatToInt *instruction) { |
| 26081 | ZigType *dest_type, IrInstGen *operand, AstNode *operand_source_node) | 26085 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 26082 | { | 26086 | if (type_is_invalid(dest_type)) |
| 26083 | if (operand->value->type->id == ZigTypeIdComptimeInt) { | 26087 | return ira->codegen->invalid_inst_gen; |
| 26084 | return ir_implicit_cast(ira, operand, dest_type); | | |
| 26085 | } | | |
| 26086 | | 26088 | |
| 26087 | if (operand->value->type->id != ZigTypeIdFloat && operand->value->type->id != ZigTypeIdComptimeFloat) { | 26089 | if (dest_type->id != ZigTypeIdInt && dest_type->id != ZigTypeIdComptimeInt) { |
| 26088 | ir_add_error_node(ira, operand_source_node, buf_sprintf("expected float type, found '%s'", | 26090 | ir_add_error(ira, &instruction->dest_type->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 26089 | buf_ptr(&operand->value->type->name))); | | |
| 26090 | return ira->codegen->invalid_inst_gen; | 26091 | return ira->codegen->invalid_inst_gen; |
| 26091 | } | 26092 | } |
| 26092 | | 26093 | |
| 26093 | return ir_resolve_cast(ira, source_instr, operand, dest_type, CastOpFloatToInt); | 26094 | IrInstGen *target = instruction->target->child; |
| 26094 | } | 26095 | if (type_is_invalid(target->value->type)) |
| 26095 | | | |
| 26096 | static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcFloatToInt *instruction) { | | |
| 26097 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); | | |
| 26098 | if (type_is_invalid(dest_type)) | | |
| 26099 | return ira->codegen->invalid_inst_gen; | 26096 | return ira->codegen->invalid_inst_gen; |
| 26100 | | 26097 | |
| 26101 | IrInstGen *operand = instruction->target->child; | 26098 | if (target->value->type->id == ZigTypeIdComptimeInt) { |
| 26102 | if (type_is_invalid(operand->value->type)) | 26099 | return ir_implicit_cast(ira, target, dest_type); |
| | 26100 | } |
| | 26101 | |
| | 26102 | if (target->value->type->id != ZigTypeIdFloat && target->value->type->id != ZigTypeIdComptimeFloat) { |
| | 26103 | ir_add_error_node(ira, target->base.source_node, buf_sprintf("expected float type, found '%s'", |
| | 26104 | buf_ptr(&target->value->type->name))); |
| 26103 | return ira->codegen->invalid_inst_gen; | 26105 | return ira->codegen->invalid_inst_gen; |
| | 26106 | } |
| 26104 | | 26107 | |
| 26105 | return ir_analyze_float_to_int(ira, &instruction->base.base, dest_type, operand, | 26108 | return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpFloatToInt); |
| 26106 | instruction->target->base.source_node); | | |
| 26107 | } | 26109 | } |
| 26108 | | 26110 | |
| 26109 | static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErrToInt *instruction) { | 26111 | static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErrToInt *instruction) { |