| ... | ... | @@ -8436,14 +8436,16 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 8436 | 8436 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 8437 | 8437 | if (!val) |
| 8438 | 8438 | return ira->codegen->invalid_instruction; |
| 8439 | | BigInt enum_member_count; |
| 8440 | | bigint_init_unsigned(&enum_member_count, wanted_type->data.enumeration.src_field_count); |
| 8441 | | if (bigint_cmp(&val->data.x_bigint, &enum_member_count) != CmpLT) { |
| 8439 | |
| 8440 | TypeEnumField *field = find_enum_field_by_tag(wanted_type, &val->data.x_bigint); |
| 8441 | if (field == nullptr) { |
| 8442 | 8442 | Buf *val_buf = buf_alloc(); |
| 8443 | 8443 | bigint_append_buf(val_buf, &val->data.x_bigint, 10); |
| 8444 | | ir_add_error(ira, source_instr, |
| 8445 | | buf_sprintf("integer value %s too big for enum '%s' which has %" PRIu32 " fields", |
| 8446 | | buf_ptr(val_buf), buf_ptr(&wanted_type->name), wanted_type->data.enumeration.src_field_count)); |
| 8444 | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 8445 | buf_sprintf("enum '%s' has no tag matching integer value %s", |
| 8446 | buf_ptr(&wanted_type->name), buf_ptr(val_buf))); |
| 8447 | add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node, |
| 8448 | buf_sprintf("'%s' declared here", buf_ptr(&wanted_type->name))); |
| 8447 | 8449 | return ira->codegen->invalid_instruction; |
| 8448 | 8450 | } |
| 8449 | 8451 | |
| ... | ... | @@ -8827,7 +8829,17 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8827 | 8829 | if (actual_type->id == TypeTableEntryIdNumLitFloat || |
| 8828 | 8830 | actual_type->id == TypeTableEntryIdNumLitInt) |
| 8829 | 8831 | { |
| 8830 | | if (wanted_type->id == TypeTableEntryIdPointer && |
| 8832 | if (wanted_type->id == TypeTableEntryIdEnum) { |
| 8833 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value); |
| 8834 | if (type_is_invalid(cast1->value.type)) |
| 8835 | return ira->codegen->invalid_instruction; |
| 8836 | |
| 8837 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 8838 | if (type_is_invalid(cast2->value.type)) |
| 8839 | return ira->codegen->invalid_instruction; |
| 8840 | |
| 8841 | return cast2; |
| 8842 | } else if (wanted_type->id == TypeTableEntryIdPointer && |
| 8831 | 8843 | wanted_type->data.pointer.is_const) |
| 8832 | 8844 | { |
| 8833 | 8845 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value); |