| ... | @@ -10560,22 +10560,33 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so | ... | @@ -10560,22 +10560,33 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 10560 | assert(union_field != nullptr); | 10560 | assert(union_field != nullptr); |
| 10561 | if ((err = type_resolve(ira->codegen, union_field->type_entry, ResolveStatusZeroBitsKnown))) | 10561 | if ((err = type_resolve(ira->codegen, union_field->type_entry, ResolveStatusZeroBitsKnown))) |
| 10562 | return ira->codegen->invalid_instruction; | 10562 | return ira->codegen->invalid_instruction; |
| 10563 | if (type_has_bits(union_field->type_entry)) { | 10563 | |
| 10564 | AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at( | 10564 | switch (type_has_one_possible_value(ira->codegen, union_field->type_entry)) { |
| 10565 | union_field->enum_field->decl_index); | 10565 | case OnePossibleValueInvalid: |
| 10566 | ErrorMsg *msg = ir_add_error(ira, source_instr, | 10566 | return ira->codegen->invalid_instruction; |
| 10567 | buf_sprintf("cast to union '%s' must initialize '%s' field '%s'", | 10567 | case OnePossibleValueNo: { |
| 10568 | buf_ptr(&wanted_type->name), | 10568 | AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at( |
| 10569 | buf_ptr(&union_field->type_entry->name), | 10569 | union_field->enum_field->decl_index); |
| 10570 | buf_ptr(union_field->name))); | 10570 | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 10571 | add_error_note(ira->codegen, msg, field_node, | 10571 | buf_sprintf("cast to union '%s' must initialize '%s' field '%s'", |
| 10572 | buf_sprintf("field '%s' declared here", buf_ptr(union_field->name))); | 10572 | buf_ptr(&wanted_type->name), |
| 10573 | return ira->codegen->invalid_instruction; | 10573 | buf_ptr(&union_field->type_entry->name), |
| | 10574 | buf_ptr(union_field->name))); |
| | 10575 | add_error_note(ira->codegen, msg, field_node, |
| | 10576 | buf_sprintf("field '%s' declared here", buf_ptr(union_field->name))); |
| | 10577 | return ira->codegen->invalid_instruction; |
| | 10578 | } |
| | 10579 | case OnePossibleValueYes: |
| | 10580 | break; |
| 10574 | } | 10581 | } |
| | 10582 | |
| 10575 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); | 10583 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 10576 | result->value.special = ConstValSpecialStatic; | 10584 | result->value.special = ConstValSpecialStatic; |
| 10577 | result->value.type = wanted_type; | 10585 | result->value.type = wanted_type; |
| 10578 | bigint_init_bigint(&result->value.data.x_union.tag, &val->data.x_enum_tag); | 10586 | bigint_init_bigint(&result->value.data.x_union.tag, &val->data.x_enum_tag); |
| | 10587 | result->value.data.x_union.payload = create_const_vals(1); |
| | 10588 | result->value.data.x_union.payload->special = ConstValSpecialStatic; |
| | 10589 | result->value.data.x_union.payload->type = union_field->type_entry; |
| 10579 | return result; | 10590 | return result; |
| 10580 | } | 10591 | } |
| 10581 | | 10592 | |
| ... | @@ -15506,13 +15517,6 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -15506,13 +15517,6 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 15506 | ConstExprValue *payload_val = union_val->data.x_union.payload; | 15517 | ConstExprValue *payload_val = union_val->data.x_union.payload; |
| 15507 | | 15518 | |
| 15508 | ZigType *field_type = field->type_entry; | 15519 | ZigType *field_type = field->type_entry; |
| 15509 | if (field_type->id == ZigTypeIdVoid) { | | |
| 15510 | assert(payload_val == nullptr); | | |
| 15511 | payload_val = create_const_vals(1); | | |
| 15512 | payload_val->special = ConstValSpecialStatic; | | |
| 15513 | payload_val->type = field_type; | | |
| 15514 | } | | |
| 15515 | | | |
| 15516 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, | 15520 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, |
| 15517 | is_const, is_volatile, PtrLenSingle, 0, 0, 0); | 15521 | is_const, is_volatile, PtrLenSingle, 0, 0, 0); |
| 15518 | | 15522 | |
| ... | @@ -18038,6 +18042,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr | ... | @@ -18038,6 +18042,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 18038 | if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown))) | 18042 | if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown))) |
| 18039 | return err; | 18043 | return err; |
| 18040 | | 18044 | |
| | 18045 | auto entry = ira->codegen->type_info_cache.maybe_get(type_entry); |
| | 18046 | if (entry != nullptr) { |
| | 18047 | *out = entry->value; |
| | 18048 | return ErrorNone; |
| | 18049 | } |
| | 18050 | |
| 18041 | ConstExprValue *result = nullptr; | 18051 | ConstExprValue *result = nullptr; |
| 18042 | switch (type_entry->id) { | 18052 | switch (type_entry->id) { |
| 18043 | case ZigTypeIdInvalid: | 18053 | case ZigTypeIdInvalid: |
| ... | @@ -18052,19 +18062,8 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr | ... | @@ -18052,19 +18062,8 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 18052 | case ZigTypeIdNull: | 18062 | case ZigTypeIdNull: |
| 18053 | case ZigTypeIdArgTuple: | 18063 | case ZigTypeIdArgTuple: |
| 18054 | case ZigTypeIdOpaque: | 18064 | case ZigTypeIdOpaque: |
| 18055 | *out = nullptr; | 18065 | result = &ira->codegen->const_void_val; |
| 18056 | return ErrorNone; | 18066 | break; |
| 18057 | default: | | |
| 18058 | { | | |
| 18059 | // Lookup an available value in our cache. | | |
| 18060 | auto entry = ira->codegen->type_info_cache.maybe_get(type_entry); | | |
| 18061 | if (entry != nullptr) { | | |
| 18062 | *out = entry->value; | | |
| 18063 | return ErrorNone; | | |
| 18064 | } | | |
| 18065 | | | |
| 18066 | // Fallthrough if we don't find one. | | |
| 18067 | } | | |
| 18068 | case ZigTypeIdInt: | 18067 | case ZigTypeIdInt: |
| 18069 | { | 18068 | { |
| 18070 | result = create_const_vals(1); | 18069 | result = create_const_vals(1); |
| ... | @@ -18636,7 +18635,6 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira, | ... | @@ -18636,7 +18635,6 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 18636 | out_val->data.x_union.payload = payload; | 18635 | out_val->data.x_union.payload = payload; |
| 18637 | | 18636 | |
| 18638 | if (payload != nullptr) { | 18637 | if (payload != nullptr) { |
| 18639 | assert(payload->type->id == ZigTypeIdStruct); | | |
| 18640 | payload->parent.id = ConstParentIdUnion; | 18638 | payload->parent.id = ConstParentIdUnion; |
| 18641 | payload->parent.data.p_union.union_val = out_val; | 18639 | payload->parent.data.p_union.union_val = out_val; |
| 18642 | } | 18640 | } |