| ... | @@ -5486,8 +5486,8 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -5486,8 +5486,8 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode |
| 5486 | ptr_len, align_value, bit_offset_start, host_int_bytes, is_allow_zero); | 5486 | ptr_len, align_value, bit_offset_start, host_int_bytes, is_allow_zero); |
| 5487 | } | 5487 | } |
| 5488 | | 5488 | |
| 5489 | static IrInstruction *ir_gen_catch_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node, AstNode *expr_node, | 5489 | static IrInstruction *ir_gen_catch_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 5490 | LVal lval) | 5490 | AstNode *expr_node, LVal lval, ResultLoc *result_loc) |
| 5491 | { | 5491 | { |
| 5492 | IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); | 5492 | IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 5493 | if (err_union_ptr == irb->codegen->invalid_instruction) | 5493 | if (err_union_ptr == irb->codegen->invalid_instruction) |
| ... | @@ -5500,7 +5500,8 @@ static IrInstruction *ir_gen_catch_unreachable(IrBuilder *irb, Scope *scope, Ast | ... | @@ -5500,7 +5500,8 @@ static IrInstruction *ir_gen_catch_unreachable(IrBuilder *irb, Scope *scope, Ast |
| 5500 | if (lval == LValPtr) | 5500 | if (lval == LValPtr) |
| 5501 | return payload_ptr; | 5501 | return payload_ptr; |
| 5502 | | 5502 | |
| 5503 | return ir_build_load_ptr(irb, scope, source_node, payload_ptr); | 5503 | IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, source_node, payload_ptr); |
| | 5504 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); |
| 5504 | } | 5505 | } |
| 5505 | | 5506 | |
| 5506 | static IrInstruction *ir_gen_bool_not(IrBuilder *irb, Scope *scope, AstNode *node) { | 5507 | static IrInstruction *ir_gen_bool_not(IrBuilder *irb, Scope *scope, AstNode *node) { |
| ... | @@ -6872,6 +6873,7 @@ static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -6872,6 +6873,7 @@ static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNo |
| 6872 | assert(node->type == NodeTypeCompTime); | 6873 | assert(node->type == NodeTypeCompTime); |
| 6873 | | 6874 | |
| 6874 | Scope *child_scope = create_comptime_scope(irb->codegen, node, parent_scope); | 6875 | Scope *child_scope = create_comptime_scope(irb->codegen, node, parent_scope); |
| | 6876 | // purposefully pass null for result_loc and let EndExpr handle it |
| 6875 | return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval, nullptr); | 6877 | return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval, nullptr); |
| 6876 | } | 6878 | } |
| 6877 | | 6879 | |
| ... | @@ -7072,7 +7074,9 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node) | ... | @@ -7072,7 +7074,9 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node) |
| 7072 | return ir_build_slice(irb, scope, node, ptr_value, start_value, end_value, true); | 7074 | return ir_build_slice(irb, scope, node, ptr_value, start_value, end_value, true); |
| 7073 | } | 7075 | } |
| 7074 | | 7076 | |
| 7075 | static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode *node) { | 7077 | static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| | 7078 | ResultLoc *result_loc) |
| | 7079 | { |
| 7076 | assert(node->type == NodeTypeUnwrapErrorExpr); | 7080 | assert(node->type == NodeTypeUnwrapErrorExpr); |
| 7077 | | 7081 | |
| 7078 | AstNode *op1_node = node->data.unwrap_err_expr.op1; | 7082 | AstNode *op1_node = node->data.unwrap_err_expr.op1; |
| ... | @@ -7086,7 +7090,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -7086,7 +7090,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 7086 | add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name))); | 7090 | add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name))); |
| 7087 | return irb->codegen->invalid_instruction; | 7091 | return irb->codegen->invalid_instruction; |
| 7088 | } | 7092 | } |
| 7089 | return ir_gen_catch_unreachable(irb, parent_scope, node, op1_node, LValNone); | 7093 | return ir_gen_catch_unreachable(irb, parent_scope, node, op1_node, lval, result_loc); |
| 7090 | } | 7094 | } |
| 7091 | | 7095 | |
| 7092 | | 7096 | |
| ... | @@ -7107,7 +7111,9 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -7107,7 +7111,9 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 7107 | IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk"); | 7111 | IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk"); |
| 7108 | IrBasicBlock *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError"); | 7112 | IrBasicBlock *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError"); |
| 7109 | IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd"); | 7113 | IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd"); |
| 7110 | ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime); | 7114 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime); |
| | 7115 | |
| | 7116 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, ok_block, end_block, result_loc); |
| 7111 | | 7117 | |
| 7112 | ir_set_cursor_at_end_and_append_block(irb, err_block); | 7118 | ir_set_cursor_at_end_and_append_block(irb, err_block); |
| 7113 | Scope *err_scope; | 7119 | Scope *err_scope; |
| ... | @@ -7124,7 +7130,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -7124,7 +7130,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 7124 | } else { | 7130 | } else { |
| 7125 | err_scope = parent_scope; | 7131 | err_scope = parent_scope; |
| 7126 | } | 7132 | } |
| 7127 | IrInstruction *err_result = ir_gen_node(irb, op2_node, err_scope); | 7133 | IrInstruction *err_result = ir_gen_node_extra(irb, op2_node, err_scope, lval, &peer_parent->peers[0].base); |
| 7128 | if (err_result == irb->codegen->invalid_instruction) | 7134 | if (err_result == irb->codegen->invalid_instruction) |
| 7129 | return irb->codegen->invalid_instruction; | 7135 | return irb->codegen->invalid_instruction; |
| 7130 | IrBasicBlock *after_err_block = irb->current_basic_block; | 7136 | IrBasicBlock *after_err_block = irb->current_basic_block; |
| ... | @@ -7134,6 +7140,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -7134,6 +7140,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 7134 | ir_set_cursor_at_end_and_append_block(irb, ok_block); | 7140 | ir_set_cursor_at_end_and_append_block(irb, ok_block); |
| 7135 | IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, parent_scope, node, err_union_ptr, false); | 7141 | IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, parent_scope, node, err_union_ptr, false); |
| 7136 | IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); | 7142 | IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); |
| | 7143 | ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers[1].base); |
| 7137 | IrBasicBlock *after_ok_block = irb->current_basic_block; | 7144 | IrBasicBlock *after_ok_block = irb->current_basic_block; |
| 7138 | ir_build_br(irb, parent_scope, node, end_block, is_comptime); | 7145 | ir_build_br(irb, parent_scope, node, end_block, is_comptime); |
| 7139 | | 7146 | |
| ... | @@ -7144,7 +7151,8 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -7144,7 +7151,8 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 7144 | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2); | 7151 | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2); |
| 7145 | incoming_blocks[0] = after_err_block; | 7152 | incoming_blocks[0] = after_err_block; |
| 7146 | incoming_blocks[1] = after_ok_block; | 7153 | incoming_blocks[1] = after_ok_block; |
| 7147 | return ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values); | 7154 | IrInstruction *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values); |
| | 7155 | return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc); |
| 7148 | } | 7156 | } |
| 7149 | | 7157 | |
| 7150 | static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *outer_scope, Scope *inner_scope) { | 7158 | static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *outer_scope, Scope *inner_scope) { |
| ... | @@ -7941,7 +7949,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop | ... | @@ -7941,7 +7949,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 7941 | case NodeTypeSwitchExpr: | 7949 | case NodeTypeSwitchExpr: |
| 7942 | return ir_gen_switch_expr(irb, scope, node, lval, result_loc); | 7950 | return ir_gen_switch_expr(irb, scope, node, lval, result_loc); |
| 7943 | case NodeTypeCompTime: | 7951 | case NodeTypeCompTime: |
| 7944 | return ir_gen_comptime(irb, scope, node, lval); | 7952 | return ir_expr_wrap(irb, scope, ir_gen_comptime(irb, scope, node, lval), result_loc); |
| 7945 | case NodeTypeErrorType: | 7953 | case NodeTypeErrorType: |
| 7946 | return ir_lval_wrap(irb, scope, ir_gen_error_type(irb, scope, node), lval, result_loc); | 7954 | return ir_lval_wrap(irb, scope, ir_gen_error_type(irb, scope, node), lval, result_loc); |
| 7947 | case NodeTypeBreak: | 7955 | case NodeTypeBreak: |
| ... | @@ -7955,7 +7963,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop | ... | @@ -7955,7 +7963,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 7955 | case NodeTypeSliceExpr: | 7963 | case NodeTypeSliceExpr: |
| 7956 | return ir_lval_wrap(irb, scope, ir_gen_slice(irb, scope, node), lval, result_loc); | 7964 | return ir_lval_wrap(irb, scope, ir_gen_slice(irb, scope, node), lval, result_loc); |
| 7957 | case NodeTypeUnwrapErrorExpr: | 7965 | case NodeTypeUnwrapErrorExpr: |
| 7958 | return ir_lval_wrap(irb, scope, ir_gen_catch(irb, scope, node), lval, result_loc); | 7966 | return ir_gen_catch(irb, scope, node, lval, result_loc); |
| 7959 | case NodeTypeContainerDecl: | 7967 | case NodeTypeContainerDecl: |
| 7960 | return ir_lval_wrap(irb, scope, ir_gen_container_decl(irb, scope, node), lval, result_loc); | 7968 | return ir_lval_wrap(irb, scope, ir_gen_container_decl(irb, scope, node), lval, result_loc); |
| 7961 | case NodeTypeFnProto: | 7969 | case NodeTypeFnProto: |
| ... | @@ -14485,8 +14493,21 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s | ... | @@ -14485,8 +14493,21 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 14485 | case ResultLocIdInvalid: | 14493 | case ResultLocIdInvalid: |
| 14486 | case ResultLocIdPeerParent: | 14494 | case ResultLocIdPeerParent: |
| 14487 | zig_unreachable(); | 14495 | zig_unreachable(); |
| 14488 | case ResultLocIdNone: | 14496 | case ResultLocIdNone: { |
| 14489 | return nullptr; | 14497 | if (value != nullptr) { |
| | 14498 | return nullptr; |
| | 14499 | } |
| | 14500 | // need to return a result location and don't have one. use a stack allocation |
| | 14501 | IrInstructionAllocaGen *alloca_gen = ir_create_alloca_gen(ira, suspend_source_instr, 0, ""); |
| | 14502 | alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, |
| | 14503 | PtrLenSingle, 0, 0, 0, false); |
| | 14504 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| | 14505 | if (fn_entry != nullptr) { |
| | 14506 | fn_entry->alloca_gen_list.append(alloca_gen); |
| | 14507 | } |
| | 14508 | result_loc->resolved_loc = &alloca_gen->base; |
| | 14509 | return result_loc->resolved_loc; |
| | 14510 | } |
| 14490 | case ResultLocIdVar: { | 14511 | case ResultLocIdVar: { |
| 14491 | ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc); | 14512 | ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc); |
| 14492 | assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc); | 14513 | assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc); |