| ... | @@ -8422,16 +8422,6 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour | ... | @@ -8422,16 +8422,6 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 8422 | if (type_is_invalid(wanted_type)) | 8422 | if (type_is_invalid(wanted_type)) |
| 8423 | return ira->codegen->invalid_instruction; | 8423 | return ira->codegen->invalid_instruction; |
| 8424 | | 8424 | |
| 8425 | if (actual_type != wanted_type->data.enumeration.tag_int_type) { | | |
| 8426 | ir_add_error(ira, source_instr, | | |
| 8427 | buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'", | | |
| 8428 | buf_ptr(&actual_type->name), | | |
| 8429 | buf_ptr(&wanted_type->data.enumeration.tag_int_type->name))); | | |
| 8430 | return ira->codegen->invalid_instruction; | | |
| 8431 | } | | |
| 8432 | | | |
| 8433 | assert(actual_type->id == TypeTableEntryIdInt); | | |
| 8434 | | | |
| 8435 | if (instr_is_comptime(target)) { | 8425 | if (instr_is_comptime(target)) { |
| 8436 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); | 8426 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 8437 | if (!val) | 8427 | if (!val) |
| ... | @@ -8453,6 +8443,17 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour | ... | @@ -8453,6 +8443,17 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 8453 | return result; | 8443 | return result; |
| 8454 | } | 8444 | } |
| 8455 | | 8445 | |
| | 8446 | if (actual_type != wanted_type->data.enumeration.tag_int_type) { |
| | 8447 | ir_add_error(ira, source_instr, |
| | 8448 | buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'", |
| | 8449 | buf_ptr(&actual_type->name), |
| | 8450 | buf_ptr(&wanted_type->data.enumeration.tag_int_type->name))); |
| | 8451 | return ira->codegen->invalid_instruction; |
| | 8452 | } |
| | 8453 | |
| | 8454 | assert(actual_type->id == TypeTableEntryIdInt); |
| | 8455 | |
| | 8456 | |
| 8456 | IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope, | 8457 | IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope, |
| 8457 | source_instr->source_node, target); | 8458 | source_instr->source_node, target); |
| 8458 | result->value.type = wanted_type; | 8459 | result->value.type = wanted_type; |
| ... | @@ -8822,6 +8823,20 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8822,6 +8823,20 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8822 | } | 8823 | } |
| 8823 | } | 8824 | } |
| 8824 | | 8825 | |
| | 8826 | // explicit cast from integer to enum type with no payload |
| | 8827 | if ((actual_type->id == TypeTableEntryIdInt || actual_type->id == TypeTableEntryIdNumLitInt) && |
| | 8828 | wanted_type->id == TypeTableEntryIdEnum) |
| | 8829 | { |
| | 8830 | return ir_analyze_int_to_enum(ira, source_instr, value, wanted_type); |
| | 8831 | } |
| | 8832 | |
| | 8833 | // explicit cast from enum type with no payload to integer |
| | 8834 | if ((wanted_type->id == TypeTableEntryIdInt || wanted_type->id == TypeTableEntryIdNumLitInt) && |
| | 8835 | actual_type->id == TypeTableEntryIdEnum) |
| | 8836 | { |
| | 8837 | return ir_analyze_enum_to_int(ira, source_instr, value, wanted_type); |
| | 8838 | } |
| | 8839 | |
| 8825 | // explicit cast from number literal to another type | 8840 | // explicit cast from number literal to another type |
| 8826 | // explicit cast from number literal to &const integer | 8841 | // explicit cast from number literal to &const integer |
| 8827 | if (actual_type->id == TypeTableEntryIdNumLitFloat || | 8842 | if (actual_type->id == TypeTableEntryIdNumLitFloat || |
| ... | @@ -8886,16 +8901,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -8886,16 +8901,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8886 | return ir_analyze_int_to_err(ira, source_instr, value); | 8901 | return ir_analyze_int_to_err(ira, source_instr, value); |
| 8887 | } | 8902 | } |
| 8888 | | 8903 | |
| 8889 | // explicit cast from integer to enum type with no payload | | |
| 8890 | if (actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdEnum) { | | |
| 8891 | return ir_analyze_int_to_enum(ira, source_instr, value, wanted_type); | | |
| 8892 | } | | |
| 8893 | | | |
| 8894 | // explicit cast from enum type with no payload to integer | | |
| 8895 | if (wanted_type->id == TypeTableEntryIdInt && actual_type->id == TypeTableEntryIdEnum) { | | |
| 8896 | return ir_analyze_enum_to_int(ira, source_instr, value, wanted_type); | | |
| 8897 | } | | |
| 8898 | | | |
| 8899 | // explicit cast from union to the enum type of the union | 8904 | // explicit cast from union to the enum type of the union |
| 8900 | if (actual_type->id == TypeTableEntryIdUnion && wanted_type->id == TypeTableEntryIdEnum) { | 8905 | if (actual_type->id == TypeTableEntryIdUnion && wanted_type->id == TypeTableEntryIdEnum) { |
| 8901 | type_ensure_zero_bits_known(ira->codegen, actual_type); | 8906 | type_ensure_zero_bits_known(ira->codegen, actual_type); |