| ... | @@ -166,6 +166,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc | ... | @@ -166,6 +166,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 166 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); | 166 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); |
| 167 | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, | 167 | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 168 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing); | 168 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing); |
| | 169 | static void ir_assert(bool ok, IrInstruction *source_instruction); |
| 169 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var); | 170 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var); |
| 170 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); | 171 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); |
| 171 | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, ResultLoc *result_loc); | 172 | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, ResultLoc *result_loc); |
| ... | @@ -904,6 +905,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionResolveResult *) | ... | @@ -904,6 +905,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionResolveResult *) |
| 904 | return IrInstructionIdResolveResult; | 905 | return IrInstructionIdResolveResult; |
| 905 | } | 906 | } |
| 906 | | 907 | |
| | 908 | static constexpr IrInstructionId ir_instruction_id(IrInstructionResetResult *) { |
| | 909 | return IrInstructionIdResetResult; |
| | 910 | } |
| | 911 | |
| 907 | static constexpr IrInstructionId ir_instruction_id(IrInstructionResultPtr *) { | 912 | static constexpr IrInstructionId ir_instruction_id(IrInstructionResultPtr *) { |
| 908 | return IrInstructionIdResultPtr; | 913 | return IrInstructionIdResultPtr; |
| 909 | } | 914 | } |
| ... | @@ -2865,6 +2870,15 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN | ... | @@ -2865,6 +2870,15 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN |
| 2865 | return &instruction->base; | 2870 | return &instruction->base; |
| 2866 | } | 2871 | } |
| 2867 | | 2872 | |
| | 2873 | static IrInstruction *ir_build_reset_result(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| | 2874 | ResultLoc *result_loc) |
| | 2875 | { |
| | 2876 | IrInstructionResetResult *instruction = ir_build_instruction<IrInstructionResetResult>(irb, scope, source_node); |
| | 2877 | instruction->result_loc = result_loc; |
| | 2878 | |
| | 2879 | return &instruction->base; |
| | 2880 | } |
| | 2881 | |
| 2868 | static IrInstruction *ir_build_result_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, | 2882 | static IrInstruction *ir_build_result_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2869 | ResultLoc *result_loc, IrInstruction *result) | 2883 | ResultLoc *result_loc, IrInstruction *result) |
| 2870 | { | 2884 | { |
| ... | @@ -3540,6 +3554,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, | ... | @@ -3540,6 +3554,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3540 | { | 3554 | { |
| 3541 | ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1); | 3555 | ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1); |
| 3542 | result_loc_ret->base.id = ResultLocIdReturn; | 3556 | result_loc_ret->base.id = ResultLocIdReturn; |
| | 3557 | ir_build_reset_result(irb, scope, node, &result_loc_ret->base); |
| 3543 | | 3558 | |
| 3544 | IrInstruction *return_value; | 3559 | IrInstruction *return_value; |
| 3545 | if (expr_node) { | 3560 | if (expr_node) { |
| ... | @@ -3929,7 +3944,7 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -3929,7 +3944,7 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod |
| 3929 | return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr); | 3944 | return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr); |
| 3930 | } | 3945 | } |
| 3931 | | 3946 | |
| 3932 | static ResultLocPeerParent *create_binary_result_peers(IrInstruction *cond_br_inst, | 3947 | static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilder *irb, IrInstruction *cond_br_inst, |
| 3933 | IrBasicBlock *else_block, IrBasicBlock *endif_block, ResultLoc *parent, IrInstruction *is_comptime) | 3948 | IrBasicBlock *else_block, IrBasicBlock *endif_block, ResultLoc *parent, IrInstruction *is_comptime) |
| 3934 | { | 3949 | { |
| 3935 | ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1); | 3950 | ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1); |
| ... | @@ -3948,6 +3963,13 @@ static ResultLocPeerParent *create_binary_result_peers(IrInstruction *cond_br_in | ... | @@ -3948,6 +3963,13 @@ static ResultLocPeerParent *create_binary_result_peers(IrInstruction *cond_br_in |
| 3948 | peer_parent->peers[1].base.source_instruction = cond_br_inst; | 3963 | peer_parent->peers[1].base.source_instruction = cond_br_inst; |
| 3949 | peer_parent->peers[1].parent = peer_parent; | 3964 | peer_parent->peers[1].parent = peer_parent; |
| 3950 | peer_parent->peers[1].next_bb = endif_block; | 3965 | peer_parent->peers[1].next_bb = endif_block; |
| | 3966 | |
| | 3967 | IrInstruction *popped_inst = irb->current_basic_block->instruction_list.pop(); |
| | 3968 | ir_assert(popped_inst == cond_br_inst, cond_br_inst); |
| | 3969 | |
| | 3970 | ir_build_reset_result(irb, cond_br_inst->scope, cond_br_inst->source_node, &peer_parent->base); |
| | 3971 | irb->current_basic_block->instruction_list.append(popped_inst); |
| | 3972 | |
| 3951 | return peer_parent; | 3973 | return peer_parent; |
| 3952 | } | 3974 | } |
| 3953 | | 3975 | |
| ... | @@ -3978,8 +4000,8 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -3978,8 +4000,8 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode |
| 3978 | IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd"); | 4000 | IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd"); |
| 3979 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime); | 4001 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime); |
| 3980 | | 4002 | |
| 3981 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, ok_block, end_block, result_loc, | 4003 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, |
| 3982 | is_comptime); | 4004 | result_loc, is_comptime); |
| 3983 | | 4005 | |
| 3984 | ir_set_cursor_at_end_and_append_block(irb, null_block); | 4006 | ir_set_cursor_at_end_and_append_block(irb, null_block); |
| 3985 | IrInstruction *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, lval, &peer_parent->peers[0].base); | 4007 | IrInstruction *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, lval, &peer_parent->peers[0].base); |
| ... | @@ -5006,6 +5028,8 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5006,6 +5028,8 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5006 | ir_ref_instruction(dest_type, irb->current_basic_block); | 5028 | ir_ref_instruction(dest_type, irb->current_basic_block); |
| 5007 | result_loc_bit_cast->parent = result_loc; | 5029 | result_loc_bit_cast->parent = result_loc; |
| 5008 | | 5030 | |
| | 5031 | ir_build_reset_result(irb, scope, node, &result_loc_bit_cast->base); |
| | 5032 | |
| 5009 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 5033 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5010 | IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone, | 5034 | IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone, |
| 5011 | &result_loc_bit_cast->base); | 5035 | &result_loc_bit_cast->base); |
| ... | @@ -5494,8 +5518,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -5494,8 +5518,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 5494 | | 5518 | |
| 5495 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, condition->source_node, condition, | 5519 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, condition->source_node, condition, |
| 5496 | then_block, else_block, is_comptime); | 5520 | then_block, else_block, is_comptime); |
| 5497 | | 5521 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block, |
| 5498 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, endif_block, | | |
| 5499 | result_loc, is_comptime); | 5522 | result_loc, is_comptime); |
| 5500 | | 5523 | |
| 5501 | ir_set_cursor_at_end_and_append_block(irb, then_block); | 5524 | ir_set_cursor_at_end_and_append_block(irb, then_block); |
| ... | @@ -5832,11 +5855,14 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A | ... | @@ -5832,11 +5855,14 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 5832 | zig_unreachable(); | 5855 | zig_unreachable(); |
| 5833 | } | 5856 | } |
| 5834 | | 5857 | |
| 5835 | static ResultLocVar *create_var_result_loc(IrInstruction *alloca, ZigVar *var) { | 5858 | static ResultLocVar *ir_build_var_result_loc(IrBuilder *irb, IrInstruction *alloca, ZigVar *var) { |
| 5836 | ResultLocVar *result_loc_var = allocate<ResultLocVar>(1); | 5859 | ResultLocVar *result_loc_var = allocate<ResultLocVar>(1); |
| 5837 | result_loc_var->base.id = ResultLocIdVar; | 5860 | result_loc_var->base.id = ResultLocIdVar; |
| 5838 | result_loc_var->base.source_instruction = alloca; | 5861 | result_loc_var->base.source_instruction = alloca; |
| 5839 | result_loc_var->var = var; | 5862 | result_loc_var->var = var; |
| | 5863 | |
| | 5864 | ir_build_reset_result(irb, alloca->scope, alloca->source_node, &result_loc_var->base); |
| | 5865 | |
| 5840 | return result_loc_var; | 5866 | return result_loc_var; |
| 5841 | } | 5867 | } |
| 5842 | | 5868 | |
| ... | @@ -5844,7 +5870,7 @@ static void build_decl_var_and_init(IrBuilder *irb, Scope *scope, AstNode *sourc | ... | @@ -5844,7 +5870,7 @@ static void build_decl_var_and_init(IrBuilder *irb, Scope *scope, AstNode *sourc |
| 5844 | IrInstruction *init, const char *name_hint, IrInstruction *is_comptime) | 5870 | IrInstruction *init, const char *name_hint, IrInstruction *is_comptime) |
| 5845 | { | 5871 | { |
| 5846 | IrInstruction *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime); | 5872 | IrInstruction *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime); |
| 5847 | ResultLocVar *var_result_loc = create_var_result_loc(alloca, var); | 5873 | ResultLocVar *var_result_loc = ir_build_var_result_loc(irb, alloca, var); |
| 5848 | ir_build_end_expr(irb, scope, source_node, init, &var_result_loc->base); | 5874 | ir_build_end_expr(irb, scope, source_node, init, &var_result_loc->base); |
| 5849 | ir_build_var_decl_src(irb, scope, source_node, var, nullptr, alloca); | 5875 | ir_build_var_decl_src(irb, scope, source_node, var, nullptr, alloca); |
| 5850 | } | 5876 | } |
| ... | @@ -5907,7 +5933,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -5907,7 +5933,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5907 | buf_ptr(variable_declaration->symbol), is_comptime); | 5933 | buf_ptr(variable_declaration->symbol), is_comptime); |
| 5908 | | 5934 | |
| 5909 | // Create a result location for the initialization expression. | 5935 | // Create a result location for the initialization expression. |
| 5910 | ResultLocVar *result_loc_var = create_var_result_loc(alloca, var); | 5936 | ResultLocVar *result_loc_var = ir_build_var_result_loc(irb, alloca, var); |
| 5911 | ResultLoc *init_result_loc = (type_instruction == nullptr) ? &result_loc_var->base : nullptr; | 5937 | ResultLoc *init_result_loc = (type_instruction == nullptr) ? &result_loc_var->base : nullptr; |
| 5912 | | 5938 | |
| 5913 | Scope *init_scope = is_comptime_scalar ? | 5939 | Scope *init_scope = is_comptime_scalar ? |
| ... | @@ -5983,10 +6009,11 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5983,10 +6009,11 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5983 | else_block, body_block, is_comptime); | 6009 | else_block, body_block, is_comptime); |
| 5984 | cond_br_inst->is_gen = true; | 6010 | cond_br_inst->is_gen = true; |
| 5985 | } else { | 6011 | } else { |
| 5986 | cond_br_inst = is_err; // for the purposes of the source instruction to create_binary_result_peers | 6012 | // for the purposes of the source instruction to ir_build_binary_result_peers |
| | 6013 | cond_br_inst = irb->current_basic_block->instruction_list.last(); |
| 5987 | } | 6014 | } |
| 5988 | | 6015 | |
| 5989 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, | 6016 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, end_block, |
| 5990 | result_loc, is_comptime); | 6017 | result_loc, is_comptime); |
| 5991 | | 6018 | |
| 5992 | ir_set_cursor_at_end_and_append_block(irb, body_block); | 6019 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| ... | @@ -6085,10 +6112,11 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -6085,10 +6112,11 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 6085 | body_block, else_block, is_comptime); | 6112 | body_block, else_block, is_comptime); |
| 6086 | cond_br_inst->is_gen = true; | 6113 | cond_br_inst->is_gen = true; |
| 6087 | } else { | 6114 | } else { |
| 6088 | cond_br_inst = is_non_null; // for the purposes of source instruction for create_binary_result_peers | 6115 | // for the purposes of the source instruction to ir_build_binary_result_peers |
| | 6116 | cond_br_inst = irb->current_basic_block->instruction_list.last(); |
| 6089 | } | 6117 | } |
| 6090 | | 6118 | |
| 6091 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, | 6119 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, end_block, |
| 6092 | result_loc, is_comptime); | 6120 | result_loc, is_comptime); |
| 6093 | | 6121 | |
| 6094 | ir_set_cursor_at_end_and_append_block(irb, body_block); | 6122 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| ... | @@ -6168,10 +6196,11 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -6168,10 +6196,11 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 6168 | body_block, else_block, is_comptime); | 6196 | body_block, else_block, is_comptime); |
| 6169 | cond_br_inst->is_gen = true; | 6197 | cond_br_inst->is_gen = true; |
| 6170 | } else { | 6198 | } else { |
| 6171 | cond_br_inst = cond_val; // for the source instruction arg to create_binary_result_peers | 6199 | // for the purposes of the source instruction to ir_build_binary_result_peers |
| | 6200 | cond_br_inst = irb->current_basic_block->instruction_list.last(); |
| 6172 | } | 6201 | } |
| 6173 | | 6202 | |
| 6174 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, | 6203 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, end_block, |
| 6175 | result_loc, is_comptime); | 6204 | result_loc, is_comptime); |
| 6176 | ir_set_cursor_at_end_and_append_block(irb, body_block); | 6205 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 6177 | | 6206 | |
| ... | @@ -6303,8 +6332,8 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -6303,8 +6332,8 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 6303 | IrInstruction *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond, | 6332 | IrInstruction *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond, |
| 6304 | body_block, else_block, is_comptime)); | 6333 | body_block, else_block, is_comptime)); |
| 6305 | | 6334 | |
| 6306 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, result_loc, | 6335 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, end_block, |
| 6307 | is_comptime); | 6336 | result_loc, is_comptime); |
| 6308 | | 6337 | |
| 6309 | ir_set_cursor_at_end_and_append_block(irb, body_block); | 6338 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 6310 | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, parent_scope, node, array_val_ptr, index_val, false, | 6339 | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, parent_scope, node, array_val_ptr, index_val, false, |
| ... | @@ -6683,7 +6712,7 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN | ... | @@ -6683,7 +6712,7 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN |
| 6683 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null, | 6712 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null, |
| 6684 | then_block, else_block, is_comptime); | 6713 | then_block, else_block, is_comptime); |
| 6685 | | 6714 | |
| 6686 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, endif_block, | 6715 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block, |
| 6687 | result_loc, is_comptime); | 6716 | result_loc, is_comptime); |
| 6688 | | 6717 | |
| 6689 | ir_set_cursor_at_end_and_append_block(irb, then_block); | 6718 | ir_set_cursor_at_end_and_append_block(irb, then_block); |
| ... | @@ -6765,7 +6794,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -6765,7 +6794,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6765 | IrInstruction *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err); | 6794 | IrInstruction *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err); |
| 6766 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime); | 6795 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime); |
| 6767 | | 6796 | |
| 6768 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, endif_block, | 6797 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block, |
| 6769 | result_loc, is_comptime); | 6798 | result_loc, is_comptime); |
| 6770 | | 6799 | |
| 6771 | ir_set_cursor_at_end_and_append_block(irb, ok_block); | 6800 | ir_set_cursor_at_end_and_append_block(irb, ok_block); |
| ... | @@ -7093,6 +7122,8 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -7093,6 +7122,8 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 7093 | IrInstruction *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value, | 7122 | IrInstruction *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value, |
| 7094 | check_ranges.items, check_ranges.length, else_prong != nullptr); | 7123 | check_ranges.items, check_ranges.length, else_prong != nullptr); |
| 7095 | | 7124 | |
| | 7125 | ir_build_reset_result(irb, scope, node, &peer_parent->base); |
| | 7126 | |
| 7096 | IrInstruction *br_instruction; | 7127 | IrInstruction *br_instruction; |
| 7097 | if (cases.length == 0) { | 7128 | if (cases.length == 0) { |
| 7098 | br_instruction = ir_build_br(irb, scope, node, else_block, is_comptime); | 7129 | br_instruction = ir_build_br(irb, scope, node, else_block, is_comptime); |
| ... | @@ -7377,7 +7408,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -7377,7 +7408,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 7377 | IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd"); | 7408 | IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd"); |
| 7378 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime); | 7409 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime); |
| 7379 | | 7410 | |
| 7380 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, ok_block, end_block, result_loc, | 7411 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, result_loc, |
| 7381 | is_comptime); | 7412 | is_comptime); |
| 7382 | | 7413 | |
| 7383 | ir_set_cursor_at_end_and_append_block(irb, err_block); | 7414 | ir_set_cursor_at_end_and_append_block(irb, err_block); |
| ... | @@ -8268,6 +8299,7 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc | ... | @@ -8268,6 +8299,7 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc |
| 8268 | // Create a result location indicating there is none - but if one gets created | 8299 | // Create a result location indicating there is none - but if one gets created |
| 8269 | // it will be properly distributed. | 8300 | // it will be properly distributed. |
| 8270 | result_loc = no_result_loc(); | 8301 | result_loc = no_result_loc(); |
| | 8302 | ir_build_reset_result(irb, scope, node, result_loc); |
| 8271 | } | 8303 | } |
| 8272 | IrInstruction *result = ir_gen_node_raw(irb, node, scope, lval, result_loc); | 8304 | IrInstruction *result = ir_gen_node_raw(irb, node, scope, lval, result_loc); |
| 8273 | irb->exec->invalid = irb->exec->invalid || (result == irb->codegen->invalid_instruction); | 8305 | irb->exec->invalid = irb->exec->invalid || (result == irb->codegen->invalid_instruction); |
| ... | @@ -8521,10 +8553,8 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -8521,10 +8553,8 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 8521 | // non-allocating. Basically coroutines are not supported right now until they are reworked. | 8553 | // non-allocating. Basically coroutines are not supported right now until they are reworked. |
| 8522 | args[3] = ir_build_const_usize(irb, scope, node, 1); // new_size | 8554 | args[3] = ir_build_const_usize(irb, scope, node, 1); // new_size |
| 8523 | args[4] = ir_build_const_usize(irb, scope, node, 1); // new_align | 8555 | args[4] = ir_build_const_usize(irb, scope, node, 1); // new_align |
| 8524 | ResultLocNone *result_loc_none = allocate<ResultLocNone>(1); | | |
| 8525 | result_loc_none->base.id = ResultLocIdNone; | | |
| 8526 | ir_build_call_src(irb, scope, node, nullptr, shrink_fn, arg_count, args, false, FnInlineAuto, false, nullptr, | 8556 | ir_build_call_src(irb, scope, node, nullptr, shrink_fn, arg_count, args, false, FnInlineAuto, false, nullptr, |
| 8527 | nullptr, &result_loc_none->base); | 8557 | nullptr, no_result_loc()); |
| 8528 | | 8558 | |
| 8529 | IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "Resume"); | 8559 | IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "Resume"); |
| 8530 | ir_build_cond_br(irb, scope, node, resume_awaiter, resume_block, irb->exec->coro_suspend_block, const_bool_false); | 8560 | ir_build_cond_br(irb, scope, node, resume_awaiter, resume_block, irb->exec->coro_suspend_block, const_bool_false); |
| ... | @@ -15082,6 +15112,40 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrIn | ... | @@ -15082,6 +15112,40 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrIn |
| 15082 | return ir_resolve_result(ira, &instruction->base, instruction->result_loc, implicit_elem_type, nullptr); | 15112 | return ir_resolve_result(ira, &instruction->base, instruction->result_loc, implicit_elem_type, nullptr); |
| 15083 | } | 15113 | } |
| 15084 | | 15114 | |
| | 15115 | static void ir_reset_result(ResultLoc *result_loc) { |
| | 15116 | result_loc->written = false; |
| | 15117 | result_loc->resolved_loc = nullptr; |
| | 15118 | result_loc->gen_instruction = nullptr; |
| | 15119 | result_loc->implicit_elem_type = nullptr; |
| | 15120 | // TODO handle result_loc->scope_elide = |
| | 15121 | switch (result_loc->id) { |
| | 15122 | case ResultLocIdInvalid: |
| | 15123 | zig_unreachable(); |
| | 15124 | case ResultLocIdPeerParent: { |
| | 15125 | ResultLocPeerParent *peer_parent = reinterpret_cast<ResultLocPeerParent *>(result_loc); |
| | 15126 | peer_parent->skipped = false; |
| | 15127 | peer_parent->done_resuming = false; |
| | 15128 | peer_parent->resolved_type = nullptr; |
| | 15129 | for (size_t i = 0; i < peer_parent->peer_count; i += 1) { |
| | 15130 | ir_reset_result(&peer_parent->peers[i].base); |
| | 15131 | } |
| | 15132 | break; |
| | 15133 | } |
| | 15134 | case ResultLocIdPeer: |
| | 15135 | case ResultLocIdNone: |
| | 15136 | case ResultLocIdVar: |
| | 15137 | case ResultLocIdReturn: |
| | 15138 | case ResultLocIdInstruction: |
| | 15139 | case ResultLocIdBitCast: |
| | 15140 | break; |
| | 15141 | } |
| | 15142 | } |
| | 15143 | |
| | 15144 | static IrInstruction *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstructionResetResult *instruction) { |
| | 15145 | ir_reset_result(instruction->result_loc); |
| | 15146 | return ir_const_void(ira, &instruction->base); |
| | 15147 | } |
| | 15148 | |
| 15085 | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry, | 15149 | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry, |
| 15086 | ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, | 15150 | ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, |
| 15087 | IrInstruction *async_allocator_inst) | 15151 | IrInstruction *async_allocator_inst) |
| ... | @@ -24594,6 +24658,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction | ... | @@ -24594,6 +24658,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction |
| 24594 | return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction); | 24658 | return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction); |
| 24595 | case IrInstructionIdResolveResult: | 24659 | case IrInstructionIdResolveResult: |
| 24596 | return ir_analyze_instruction_resolve_result(ira, (IrInstructionResolveResult *)instruction); | 24660 | return ir_analyze_instruction_resolve_result(ira, (IrInstructionResolveResult *)instruction); |
| | 24661 | case IrInstructionIdResetResult: |
| | 24662 | return ir_analyze_instruction_reset_result(ira, (IrInstructionResetResult *)instruction); |
| 24597 | case IrInstructionIdResultPtr: | 24663 | case IrInstructionIdResultPtr: |
| 24598 | return ir_analyze_instruction_result_ptr(ira, (IrInstructionResultPtr *)instruction); | 24664 | return ir_analyze_instruction_result_ptr(ira, (IrInstructionResultPtr *)instruction); |
| 24599 | case IrInstructionIdOpaqueType: | 24665 | case IrInstructionIdOpaqueType: |
| ... | @@ -24818,6 +24884,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -24818,6 +24884,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24818 | case IrInstructionIdSliceGen: | 24884 | case IrInstructionIdSliceGen: |
| 24819 | case IrInstructionIdOptionalWrap: | 24885 | case IrInstructionIdOptionalWrap: |
| 24820 | case IrInstructionIdVectorToArray: | 24886 | case IrInstructionIdVectorToArray: |
| | 24887 | case IrInstructionIdResetResult: |
| 24821 | return true; | 24888 | return true; |
| 24822 | | 24889 | |
| 24823 | case IrInstructionIdPhi: | 24890 | case IrInstructionIdPhi: |