From b66fb7ceae9029935e5cf3c3752d240a74b6cd7c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 5 Dec 2017 20:51:49 -0500 Subject: [PATCH] revert to master branch ir.cpp, fixes issue better than this branch --- src/ir.cpp | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/ir.cpp b/src/ir.cpp index e31cd2d1bf..86fa8c3566 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -8490,6 +8490,16 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour if (type_is_invalid(wanted_type)) return ira->codegen->invalid_instruction; + if (actual_type != wanted_type->data.enumeration.tag_int_type) { + ir_add_error(ira, source_instr, + buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'", + buf_ptr(&actual_type->name), + buf_ptr(&wanted_type->data.enumeration.tag_int_type->name))); + return ira->codegen->invalid_instruction; + } + + assert(actual_type->id == TypeTableEntryIdInt); + if (instr_is_comptime(target)) { ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) @@ -8513,17 +8523,6 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour return result; } - if (actual_type != wanted_type->data.enumeration.tag_int_type) { - ir_add_error(ira, source_instr, - buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'", - buf_ptr(&actual_type->name), - buf_ptr(&wanted_type->data.enumeration.tag_int_type->name))); - return ira->codegen->invalid_instruction; - } - - assert(actual_type->id == TypeTableEntryIdInt); - - IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope, source_instr->source_node, target); result->value.type = wanted_type; @@ -8893,20 +8892,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } } - // explicit cast from integer to enum type with no payload - if ((actual_type->id == TypeTableEntryIdInt || actual_type->id == TypeTableEntryIdNumLitInt) && - wanted_type->id == TypeTableEntryIdEnum) - { - return ir_analyze_int_to_enum(ira, source_instr, value, wanted_type); - } - - // explicit cast from enum type with no payload to integer - if ((wanted_type->id == TypeTableEntryIdInt || wanted_type->id == TypeTableEntryIdNumLitInt) && - actual_type->id == TypeTableEntryIdEnum) - { - return ir_analyze_enum_to_int(ira, source_instr, value, wanted_type); - } - // explicit cast from number literal to another type // explicit cast from number literal to &const integer if (actual_type->id == TypeTableEntryIdNumLitFloat || @@ -8981,6 +8966,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst return ir_analyze_int_to_err(ira, source_instr, value); } + // explicit cast from integer to enum type with no payload + if (actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdEnum) { + return ir_analyze_int_to_enum(ira, source_instr, value, wanted_type); + } + + // explicit cast from enum type with no payload to integer + if (wanted_type->id == TypeTableEntryIdInt && actual_type->id == TypeTableEntryIdEnum) { + return ir_analyze_enum_to_int(ira, source_instr, value, wanted_type); + } + // explicit cast from union to the enum type of the union if (actual_type->id == TypeTableEntryIdUnion && wanted_type->id == TypeTableEntryIdEnum) { type_ensure_zero_bits_known(ira->codegen, actual_type);