authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-05 20:51:49-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-05 20:51:49-05:00
logb66fb7ceae9029935e5cf3c3752d240a74b6cd7c
treeb578fe95e0e4c9179a21989b9e19934d54ef6287
parent6018dbd3391d1e71eef650aff700eab53074c308

revert to master branch ir.cpp, fixes issue better than this branch


1 files changed, 20 insertions(+), 25 deletions(-)

src/ir.cpp+20-25
......@@ -8490,6 +8490,16 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
84908490 if (type_is_invalid(wanted_type))
84918491 return ira->codegen->invalid_instruction;
84928492
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
84938503 if (instr_is_comptime(target)) {
84948504 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
84958505 if (!val)
......@@ -8513,17 +8523,6 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
85138523 return result;
85148524 }
85158525
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
85278526 IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope,
85288527 source_instr->source_node, target);
85298528 result->value.type = wanted_type;
......@@ -8893,20 +8892,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
88938892 }
88948893 }
88958894
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
89108895 // explicit cast from number literal to another type
89118896 // explicit cast from number literal to &const integer
89128897 if (actual_type->id == TypeTableEntryIdNumLitFloat ||
......@@ -8981,6 +8966,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
89818966 return ir_analyze_int_to_err(ira, source_instr, value);
89828967 }
89838968
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
89848979 // explicit cast from union to the enum type of the union
89858980 if (actual_type->id == TypeTableEntryIdUnion && wanted_type->id == TypeTableEntryIdEnum) {
89868981 type_ensure_zero_bits_known(ira->codegen, actual_type);