authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2019-03-08 17:50:42+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-11 10:55:43-04:00
logbcbb2650c5a7dca900861cc23f60374d29d50ec4
tree8147e4ec1ac7d50dbce4443a2eea2a65b94182f7
parent357813b1930579af2ba3b5004131ac9f3f80ba57
signaturelock-open Commit is signed but in an unrecognized format.

check for type_has_one_possible_value and added correct caching to TypeInfo


1 files changed, 24 insertions(+), 11 deletions(-)

src/ir.cpp+24-11
......@@ -10560,18 +10560,25 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
1056010560 assert(union_field != nullptr);
1056110561 if ((err = type_resolve(ira->codegen, union_field->type_entry, ResolveStatusZeroBitsKnown)))
1056210562 return ira->codegen->invalid_instruction;
10563 if (type_has_bits(union_field->type_entry)) {
10564 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(
10565 union_field->enum_field->decl_index);
10566 ErrorMsg *msg = ir_add_error(ira, source_instr,
10567 buf_sprintf("cast to union '%s' must initialize '%s' field '%s'",
10568 buf_ptr(&wanted_type->name),
10569 buf_ptr(&union_field->type_entry->name),
10570 buf_ptr(union_field->name)));
10571 add_error_note(ira->codegen, msg, field_node,
10572 buf_sprintf("field '%s' declared here", buf_ptr(union_field->name)));
10573 return ira->codegen->invalid_instruction;
10563
10564 switch (type_has_one_possible_value(ira->codegen, union_field->type_entry)) {
10565 case OnePossibleValueNo:
10566 case OnePossibleValueInvalid: {
10567 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(
10568 union_field->enum_field->decl_index);
10569 ErrorMsg *msg = ir_add_error(ira, source_instr,
10570 buf_sprintf("cast to union '%s' must initialize '%s' field '%s'",
10571 buf_ptr(&wanted_type->name),
10572 buf_ptr(&union_field->type_entry->name),
10573 buf_ptr(union_field->name)));
10574 add_error_note(ira->codegen, msg, field_node,
10575 buf_sprintf("field '%s' declared here", buf_ptr(union_field->name)));
10576 return ira->codegen->invalid_instruction;
10577 }
10578 case OnePossibleValueYes:
10579 break;
1057410580 }
10581
1057510582 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
1057610583 result->value.special = ConstValSpecialStatic;
1057710584 result->value.type = wanted_type;
......@@ -18034,6 +18041,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
1803418041 if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown)))
1803518042 return err;
1803618043
18044 auto entry = ira->codegen->type_info_cache.maybe_get(type_entry);
18045 if (entry != nullptr) {
18046 *out = entry->value;
18047 return ErrorNone;
18048 }
18049
1803718050 ConstExprValue *result = nullptr;
1803818051 switch (type_entry->id) {
1803918052 case ZigTypeIdInvalid: