| ... | ... | @@ -5983,7 +5983,9 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5983 | 5983 | } |
| 5984 | 5984 | } |
| 5985 | 5985 | |
| 5986 | | static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 5986 | static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| 5987 | ResultLoc *result_loc) |
| 5988 | { |
| 5987 | 5989 | assert(node->type == NodeTypeForExpr); |
| 5988 | 5990 | |
| 5989 | 5991 | AstNode *array_node = node->data.for_expr.array_expr; |
| ... | ... | @@ -6043,7 +6045,10 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 6043 | 6045 | IrInstruction *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false); |
| 6044 | 6046 | IrBasicBlock *after_cond_block = irb->current_basic_block; |
| 6045 | 6047 | IrInstruction *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node)); |
| 6046 | | ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond, body_block, else_block, is_comptime)); |
| 6048 | IrInstruction *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond, |
| 6049 | body_block, else_block, is_comptime)); |
| 6050 | |
| 6051 | ResultLocPeerParent *peer_parent = create_binary_result_peers(cond_br_inst, else_block, end_block, result_loc); |
| 6047 | 6052 | |
| 6048 | 6053 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 6049 | 6054 | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, parent_scope, node, array_val_ptr, index_val, false, PtrLenSingle); |
| ... | ... | @@ -6064,7 +6069,12 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 6064 | 6069 | loop_scope->is_comptime = is_comptime; |
| 6065 | 6070 | loop_scope->incoming_blocks = &incoming_blocks; |
| 6066 | 6071 | loop_scope->incoming_values = &incoming_values; |
| 6072 | loop_scope->lval = lval; |
| 6073 | loop_scope->result_loc = &peer_parent->peers[0].base; |
| 6067 | 6074 | |
| 6075 | // Note the body block of the loop is not the place that lval and result_loc are used - |
| 6076 | // it's actually in break statements, handled similarly to return statements. |
| 6077 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. |
| 6068 | 6078 | IrInstruction *body_result = ir_gen_node(irb, body_node, &loop_scope->base); |
| 6069 | 6079 | |
| 6070 | 6080 | if (!instr_is_unreachable(body_result)) { |
| ... | ... | @@ -6081,7 +6091,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 6081 | 6091 | if (else_node) { |
| 6082 | 6092 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 6083 | 6093 | |
| 6084 | | else_result = ir_gen_node(irb, else_node, parent_scope); |
| 6094 | else_result = ir_gen_node_extra(irb, else_node, parent_scope, lval, &peer_parent->peers[1].base); |
| 6085 | 6095 | if (else_result == irb->codegen->invalid_instruction) |
| 6086 | 6096 | return else_result; |
| 6087 | 6097 | if (!instr_is_unreachable(else_result)) |
| ... | ... | @@ -6098,7 +6108,8 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 6098 | 6108 | incoming_values.append(void_else_value); |
| 6099 | 6109 | } |
| 6100 | 6110 | |
| 6101 | | return ir_build_phi(irb, parent_scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); |
| 6111 | IrInstruction *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); |
| 6112 | return ir_expr_wrap(irb, parent_scope, phi, result_loc); |
| 6102 | 6113 | } |
| 6103 | 6114 | |
| 6104 | 6115 | static IrInstruction *ir_gen_bool_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| ... | ... | @@ -7866,7 +7877,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 7866 | 7877 | case NodeTypeWhileExpr: |
| 7867 | 7878 | return ir_gen_while_expr(irb, scope, node, lval, result_loc); |
| 7868 | 7879 | case NodeTypeForExpr: |
| 7869 | | return ir_lval_wrap(irb, scope, ir_gen_for_expr(irb, scope, node), lval, result_loc); |
| 7880 | return ir_gen_for_expr(irb, scope, node, lval, result_loc); |
| 7870 | 7881 | case NodeTypeArrayAccessExpr: |
| 7871 | 7882 | return ir_gen_array_access(irb, scope, node, lval, result_loc); |
| 7872 | 7883 | case NodeTypeReturnExpr: |