| ... | @@ -8490,6 +8490,16 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour | ... | @@ -8490,6 +8490,16 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 8490 | if (type_is_invalid(wanted_type)) | 8490 | if (type_is_invalid(wanted_type)) |
| 8491 | return ira->codegen->invalid_instruction; | 8491 | return ira->codegen->invalid_instruction; |
| 8492 | | 8492 | |
| | 8493 | if (actual_type != wanted_type->data.enumeration.tag_int_type) { |
| | 8494 | ir_add_error(ira, source_instr, |
| | 8495 | buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'", |
| | 8496 | buf_ptr(&actual_type->name), |
| | 8497 | buf_ptr(&wanted_type->data.enumeration.tag_int_type->name))); |
| | 8498 | return ira->codegen->invalid_instruction; |
| | 8499 | } |
| | 8500 | |
| | 8501 | assert(actual_type->id == TypeTableEntryIdInt); |
| | 8502 | |
| 8493 | if (instr_is_comptime(target)) { | 8503 | if (instr_is_comptime(target)) { |
| 8494 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); | 8504 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 8495 | if (!val) | 8505 | if (!val) |
| ... | @@ -8513,17 +8523,6 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour | ... | @@ -8513,17 +8523,6 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 8513 | return result; | 8523 | return result; |
| 8514 | } | 8524 | } |
| 8515 | | 8525 | |
| 8516 | if (actual_type != wanted_type->data.enumeration.tag_int_type) { | | |
| 8517 | ir_add_error(ira, source_instr, | | |
| 8518 | buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'", | | |
| 8519 | buf_ptr(&actual_type->name), | | |
| 8520 | buf_ptr(&wanted_type->data.enumeration.tag_int_type->name))); | | |
| 8521 | return ira->codegen->invalid_instruction; | | |
| 8522 | } | | |
| 8523 | | | |
| 8524 | assert(actual_type->id == TypeTableEntryIdInt); | | |
| 8525 | | | |
| 8526 | | | |
| 8527 | IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope, | 8526 | IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope, |
| 8528 | source_instr->source_node, target); | 8527 | source_instr->source_node, target); |
| 8529 | result->value.type = wanted_type; | 8528 | result->value.type = wanted_type; |
| ... | @@ -8893,20 +8892,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8893,20 +8892,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8893 | } | 8892 | } |
| 8894 | } | 8893 | } |
| 8895 | | 8894 | |
| 8896 | // explicit cast from integer to enum type with no payload | | |
| 8897 | if ((actual_type->id == TypeTableEntryIdInt || actual_type->id == TypeTableEntryIdNumLitInt) && | | |
| 8898 | wanted_type->id == TypeTableEntryIdEnum) | | |
| 8899 | { | | |
| 8900 | return ir_analyze_int_to_enum(ira, source_instr, value, wanted_type); | | |
| 8901 | } | | |
| 8902 | | | |
| 8903 | // explicit cast from enum type with no payload to integer | | |
| 8904 | if ((wanted_type->id == TypeTableEntryIdInt || wanted_type->id == TypeTableEntryIdNumLitInt) && | | |
| 8905 | actual_type->id == TypeTableEntryIdEnum) | | |
| 8906 | { | | |
| 8907 | return ir_analyze_enum_to_int(ira, source_instr, value, wanted_type); | | |
| 8908 | } | | |
| 8909 | | | |
| 8910 | // explicit cast from number literal to another type | 8895 | // explicit cast from number literal to another type |
| 8911 | // explicit cast from number literal to &const integer | 8896 | // explicit cast from number literal to &const integer |
| 8912 | if (actual_type->id == TypeTableEntryIdNumLitFloat || | 8897 | if (actual_type->id == TypeTableEntryIdNumLitFloat || |
| ... | @@ -8981,6 +8966,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8981,6 +8966,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8981 | return ir_analyze_int_to_err(ira, source_instr, value); | 8966 | return ir_analyze_int_to_err(ira, source_instr, value); |
| 8982 | } | 8967 | } |
| 8983 | | 8968 | |
| | 8969 | // explicit cast from integer to enum type with no payload |
| | 8970 | if (actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdEnum) { |
| | 8971 | return ir_analyze_int_to_enum(ira, source_instr, value, wanted_type); |
| | 8972 | } |
| | 8973 | |
| | 8974 | // explicit cast from enum type with no payload to integer |
| | 8975 | if (wanted_type->id == TypeTableEntryIdInt && actual_type->id == TypeTableEntryIdEnum) { |
| | 8976 | return ir_analyze_enum_to_int(ira, source_instr, value, wanted_type); |
| | 8977 | } |
| | 8978 | |
| 8984 | // explicit cast from union to the enum type of the union | 8979 | // explicit cast from union to the enum type of the union |
| 8985 | if (actual_type->id == TypeTableEntryIdUnion && wanted_type->id == TypeTableEntryIdEnum) { | 8980 | if (actual_type->id == TypeTableEntryIdUnion && wanted_type->id == TypeTableEntryIdEnum) { |
| 8986 | type_ensure_zero_bits_known(ira->codegen, actual_type); | 8981 | type_ensure_zero_bits_known(ira->codegen, actual_type); |