| ... | ... | @@ -1574,14 +1574,16 @@ static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *sourc |
| 1574 | 1574 | } |
| 1575 | 1575 | |
| 1576 | 1576 | static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *source_instruction, |
| 1577 | | IrInstruction *operand, ZigType *ty) |
| 1577 | IrInstruction *operand, ZigType *ty, IrInstruction *result_loc) |
| 1578 | 1578 | { |
| 1579 | 1579 | IrInstructionResizeSlice *instruction = ir_build_instruction<IrInstructionResizeSlice>(&ira->new_irb, |
| 1580 | 1580 | source_instruction->scope, source_instruction->source_node); |
| 1581 | 1581 | instruction->base.value.type = ty; |
| 1582 | 1582 | instruction->operand = operand; |
| 1583 | instruction->result_loc = result_loc; |
| 1583 | 1584 | |
| 1584 | 1585 | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| 1586 | ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 1585 | 1587 | |
| 1586 | 1588 | return &instruction->base; |
| 1587 | 1589 | } |
| ... | ... | @@ -2131,19 +2133,25 @@ static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNod |
| 2131 | 2133 | return &instruction->base; |
| 2132 | 2134 | } |
| 2133 | 2135 | |
| 2134 | | static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target) { |
| 2136 | static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target, |
| 2137 | ResultLoc *result_loc) |
| 2138 | { |
| 2135 | 2139 | IrInstructionToBytes *instruction = ir_build_instruction<IrInstructionToBytes>(irb, scope, source_node); |
| 2136 | 2140 | instruction->target = target; |
| 2141 | instruction->result_loc = result_loc; |
| 2137 | 2142 | |
| 2138 | 2143 | ir_ref_instruction(target, irb->current_basic_block); |
| 2139 | 2144 | |
| 2140 | 2145 | return &instruction->base; |
| 2141 | 2146 | } |
| 2142 | 2147 | |
| 2143 | | static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_child_type, IrInstruction *target) { |
| 2148 | static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2149 | IrInstruction *dest_child_type, IrInstruction *target, ResultLoc *result_loc) |
| 2150 | { |
| 2144 | 2151 | IrInstructionFromBytes *instruction = ir_build_instruction<IrInstructionFromBytes>(irb, scope, source_node); |
| 2145 | 2152 | instruction->dest_child_type = dest_child_type; |
| 2146 | 2153 | instruction->target = target; |
| 2154 | instruction->result_loc = result_loc; |
| 2147 | 2155 | |
| 2148 | 2156 | ir_ref_instruction(dest_child_type, irb->current_basic_block); |
| 2149 | 2157 | ir_ref_instruction(target, irb->current_basic_block); |
| ... | ... | @@ -4599,7 +4607,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4599 | 4607 | if (arg1_value == irb->codegen->invalid_instruction) |
| 4600 | 4608 | return arg1_value; |
| 4601 | 4609 | |
| 4602 | | IrInstruction *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value); |
| 4610 | IrInstruction *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value, result_loc); |
| 4603 | 4611 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 4604 | 4612 | } |
| 4605 | 4613 | case BuiltinFnIdToBytes: |
| ... | ... | @@ -4609,7 +4617,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4609 | 4617 | if (arg0_value == irb->codegen->invalid_instruction) |
| 4610 | 4618 | return arg0_value; |
| 4611 | 4619 | |
| 4612 | | IrInstruction *result = ir_build_to_bytes(irb, scope, node, arg0_value); |
| 4620 | IrInstruction *result = ir_build_to_bytes(irb, scope, node, arg0_value, result_loc); |
| 4613 | 4621 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 4614 | 4622 | } |
| 4615 | 4623 | case BuiltinFnIdIntToFloat: |
| ... | ... | @@ -5681,7 +5689,8 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 5681 | 5689 | ir_ref_instruction(elem_ptr, irb->current_basic_block); |
| 5682 | 5690 | ResultLoc *child_result_loc = &result_loc_inst->base; |
| 5683 | 5691 | |
| 5684 | | IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, child_result_loc); |
| 5692 | IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, &result_loc->scope_elide->base, |
| 5693 | LValNone, child_result_loc); |
| 5685 | 5694 | if (expr_value == irb->codegen->invalid_instruction) |
| 5686 | 5695 | return expr_value; |
| 5687 | 5696 | |
| ... | ... | @@ -14687,6 +14696,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 14687 | 14696 | if (fn_entry != nullptr) { |
| 14688 | 14697 | fn_entry->alloca_gen_list.append(alloca_gen); |
| 14689 | 14698 | } |
| 14699 | result_loc->written = true; |
| 14690 | 14700 | result_loc->resolved_loc = &alloca_gen->base; |
| 14691 | 14701 | return result_loc->resolved_loc; |
| 14692 | 14702 | } |
| ... | ... | @@ -20766,6 +20776,12 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 20766 | 20776 | } |
| 20767 | 20777 | } |
| 20768 | 20778 | |
| 20779 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 20780 | dest_slice_type, nullptr); |
| 20781 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 20782 | return result_loc; |
| 20783 | } |
| 20784 | |
| 20769 | 20785 | if (casted_value->value.data.rh_slice.id == RuntimeHintSliceIdLen) { |
| 20770 | 20786 | known_len = casted_value->value.data.rh_slice.len; |
| 20771 | 20787 | have_known_len = true; |
| ... | ... | @@ -20785,9 +20801,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 20785 | 20801 | } |
| 20786 | 20802 | } |
| 20787 | 20803 | |
| 20788 | | IrInstruction *result = ir_build_resize_slice(ira, &instruction->base, casted_value, dest_slice_type); |
| 20789 | | ir_add_alloca(ira, result, dest_slice_type); |
| 20790 | | return result; |
| 20804 | return ir_build_resize_slice(ira, &instruction->base, casted_value, dest_slice_type, result_loc); |
| 20791 | 20805 | } |
| 20792 | 20806 | |
| 20793 | 20807 | static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) { |
| ... | ... | @@ -20839,9 +20853,13 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 20839 | 20853 | return result; |
| 20840 | 20854 | } |
| 20841 | 20855 | |
| 20842 | | IrInstruction *result = ir_build_resize_slice(ira, &instruction->base, target, dest_slice_type); |
| 20843 | | ir_add_alloca(ira, result, dest_slice_type); |
| 20844 | | return result; |
| 20856 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 20857 | dest_slice_type, nullptr); |
| 20858 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 20859 | return result_loc; |
| 20860 | } |
| 20861 | |
| 20862 | return ir_build_resize_slice(ira, &instruction->base, target, dest_slice_type, result_loc); |
| 20845 | 20863 | } |
| 20846 | 20864 | |
| 20847 | 20865 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) { |