| ... | ... | @@ -1788,11 +1788,17 @@ static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *s |
| 1788 | 1788 | return &instruction->base; |
| 1789 | 1789 | } |
| 1790 | 1790 | |
| 1791 | | static IrInstruction *ir_build_err_wrap_code(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 1792 | | IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>(irb, scope, source_node); |
| 1793 | | instruction->value = value; |
| 1791 | static IrInstruction *ir_build_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instruction, |
| 1792 | ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc) |
| 1793 | { |
| 1794 | IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>( |
| 1795 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1796 | instruction->base.value.type = result_type; |
| 1797 | instruction->operand = operand; |
| 1798 | instruction->result_loc = result_loc; |
| 1794 | 1799 | |
| 1795 | | ir_ref_instruction(value, irb->current_basic_block); |
| 1800 | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| 1801 | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 1796 | 1802 | |
| 1797 | 1803 | return &instruction->base; |
| 1798 | 1804 | } |
| ... | ... | @@ -11172,7 +11178,9 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou |
| 11172 | 11178 | return result; |
| 11173 | 11179 | } |
| 11174 | 11180 | |
| 11175 | | static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { |
| 11181 | static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 11182 | ZigType *wanted_type, ResultLoc *result_loc) |
| 11183 | { |
| 11176 | 11184 | assert(wanted_type->id == ZigTypeIdErrorUnion); |
| 11177 | 11185 | |
| 11178 | 11186 | IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type); |
| ... | ... | @@ -11196,10 +11204,20 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 11196 | 11204 | return &const_instruction->base; |
| 11197 | 11205 | } |
| 11198 | 11206 | |
| 11199 | | IrInstruction *result = ir_build_err_wrap_code(&ira->new_irb, source_instr->scope, source_instr->source_node, value); |
| 11200 | | result->value.type = wanted_type; |
| 11207 | IrInstruction *result_loc_inst; |
| 11208 | if (handle_is_ptr(wanted_type)) { |
| 11209 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 11210 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr); |
| 11211 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11212 | return result_loc_inst; |
| 11213 | } |
| 11214 | } else { |
| 11215 | result_loc_inst = nullptr; |
| 11216 | } |
| 11217 | |
| 11218 | |
| 11219 | IrInstruction *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst); |
| 11201 | 11220 | result->value.data.rh_error_union = RuntimeHintErrorUnionError; |
| 11202 | | ir_add_alloca(ira, result, wanted_type); |
| 11203 | 11221 | return result; |
| 11204 | 11222 | } |
| 11205 | 11223 | |
| ... | ... | @@ -12293,7 +12311,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12293 | 12311 | if (wanted_type->id == ZigTypeIdErrorUnion && |
| 12294 | 12312 | actual_type->id == ZigTypeIdErrorSet) |
| 12295 | 12313 | { |
| 12296 | | return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type); |
| 12314 | return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type, result_loc); |
| 12297 | 12315 | } |
| 12298 | 12316 | |
| 12299 | 12317 | // cast from typed number to integer or float literal. |
| ... | ... | @@ -15615,12 +15633,16 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 15615 | 15633 | } |
| 15616 | 15634 | |
| 15617 | 15635 | FnTypeId *impl_fn_type_id = &impl_fn->type_entry->data.fn.fn_type_id; |
| 15618 | | IrInstruction *result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 15619 | | impl_fn_type_id->return_type, nullptr); |
| 15620 | | if (result_loc != nullptr && |
| 15621 | | (type_is_invalid(result_loc->value.type) || result_loc->value.type->id == ZigTypeIdUnreachable)) |
| 15622 | | { |
| 15623 | | return result_loc; |
| 15636 | IrInstruction *result_loc; |
| 15637 | if (handle_is_ptr(impl_fn_type_id->return_type)) { |
| 15638 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 15639 | impl_fn_type_id->return_type, nullptr); |
| 15640 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 15641 | return result_loc; |
| 15642 | } |
| 15643 | call_instruction->result_loc->written = true; |
| 15644 | } else { |
| 15645 | result_loc = nullptr; |
| 15624 | 15646 | } |
| 15625 | 15647 | |
| 15626 | 15648 | if (fn_type_can_fail(impl_fn_type_id)) { |
| ... | ... | @@ -15634,7 +15656,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 15634 | 15656 | return ir_finish_anal(ira, result); |
| 15635 | 15657 | } |
| 15636 | 15658 | |
| 15637 | | call_instruction->result_loc->written = handle_is_ptr(impl_fn_type_id->return_type); |
| 15638 | 15659 | assert(async_allocator_inst == nullptr); |
| 15639 | 15660 | IrInstruction *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base, |
| 15640 | 15661 | impl_fn, nullptr, impl_param_count, casted_args, fn_inline, |
| ... | ... | @@ -15733,15 +15754,18 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 15733 | 15754 | return ira->codegen->invalid_instruction; |
| 15734 | 15755 | } |
| 15735 | 15756 | |
| 15736 | | IrInstruction *result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 15737 | | return_type, nullptr); |
| 15738 | | if (result_loc != nullptr && |
| 15739 | | (type_is_invalid(result_loc->value.type) || result_loc->value.type->id == ZigTypeIdUnreachable)) |
| 15740 | | { |
| 15741 | | return result_loc; |
| 15757 | IrInstruction *result_loc; |
| 15758 | if (handle_is_ptr(return_type)) { |
| 15759 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 15760 | return_type, nullptr); |
| 15761 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 15762 | return result_loc; |
| 15763 | } |
| 15764 | call_instruction->result_loc->written = true; |
| 15765 | } else { |
| 15766 | result_loc = nullptr; |
| 15742 | 15767 | } |
| 15743 | 15768 | |
| 15744 | | call_instruction->result_loc->written = handle_is_ptr(return_type); |
| 15745 | 15769 | IrInstruction *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, |
| 15746 | 15770 | call_param_count, casted_args, fn_inline, false, nullptr, casted_new_stack, |
| 15747 | 15771 | result_loc, return_type); |
| ... | ... | @@ -24462,7 +24486,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24462 | 24486 | case IrInstructionIdHandle: |
| 24463 | 24487 | case IrInstructionIdTestErr: |
| 24464 | 24488 | case IrInstructionIdUnwrapErrCode: |
| 24465 | | case IrInstructionIdErrWrapCode: |
| 24466 | 24489 | case IrInstructionIdFnProto: |
| 24467 | 24490 | case IrInstructionIdTestComptime: |
| 24468 | 24491 | case IrInstructionIdPtrCastSrc: |
| ... | ... | @@ -24529,6 +24552,8 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24529 | 24552 | } |
| 24530 | 24553 | case IrInstructionIdErrWrapPayload: |
| 24531 | 24554 | return reinterpret_cast<IrInstructionErrWrapPayload *>(instruction)->result_loc != nullptr; |
| 24555 | case IrInstructionIdErrWrapCode: |
| 24556 | return reinterpret_cast<IrInstructionErrWrapCode *>(instruction)->result_loc != nullptr; |
| 24532 | 24557 | } |
| 24533 | 24558 | zig_unreachable(); |
| 24534 | 24559 | } |