| ... | @@ -1657,6 +1657,27 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou | ... | @@ -1657,6 +1657,27 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1657 | return &instruction->base; | 1657 | return &instruction->base; |
| 1658 | } | 1658 | } |
| 1659 | | 1659 | |
| | 1660 | static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *ptr) { |
| | 1661 | IrInstructionToPtrType *instruction = ir_build_instruction<IrInstructionToPtrType>(irb, scope, source_node); |
| | 1662 | instruction->ptr = ptr; |
| | 1663 | |
| | 1664 | ir_ref_instruction(ptr, irb->current_basic_block); |
| | 1665 | |
| | 1666 | return &instruction->base; |
| | 1667 | } |
| | 1668 | |
| | 1669 | static IrInstruction *ir_build_ptr_type_child(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| | 1670 | IrInstruction *value) |
| | 1671 | { |
| | 1672 | IrInstructionPtrTypeChild *instruction = ir_build_instruction<IrInstructionPtrTypeChild>( |
| | 1673 | irb, scope, source_node); |
| | 1674 | instruction->value = value; |
| | 1675 | |
| | 1676 | ir_ref_instruction(value, irb->current_basic_block); |
| | 1677 | |
| | 1678 | return &instruction->base; |
| | 1679 | } |
| | 1680 | |
| 1660 | static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_cold) { | 1681 | static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_cold) { |
| 1661 | IrInstructionSetCold *instruction = ir_build_instruction<IrInstructionSetCold>(irb, scope, source_node); | 1682 | IrInstructionSetCold *instruction = ir_build_instruction<IrInstructionSetCold>(irb, scope, source_node); |
| 1662 | instruction->is_cold = is_cold; | 1683 | instruction->is_cold = is_cold; |
| ... | @@ -2371,12 +2392,12 @@ static IrInstruction *ir_build_test_err(IrBuilder *irb, Scope *scope, AstNode *s | ... | @@ -2371,12 +2392,12 @@ static IrInstruction *ir_build_test_err(IrBuilder *irb, Scope *scope, AstNode *s |
| 2371 | } | 2392 | } |
| 2372 | | 2393 | |
| 2373 | static IrInstruction *ir_build_unwrap_err_code(IrBuilder *irb, Scope *scope, AstNode *source_node, | 2394 | static IrInstruction *ir_build_unwrap_err_code(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2374 | IrInstruction *err_union) | 2395 | IrInstruction *err_union_ptr) |
| 2375 | { | 2396 | { |
| 2376 | IrInstructionUnwrapErrCode *instruction = ir_build_instruction<IrInstructionUnwrapErrCode>(irb, scope, source_node); | 2397 | IrInstructionUnwrapErrCode *instruction = ir_build_instruction<IrInstructionUnwrapErrCode>(irb, scope, source_node); |
| 2377 | instruction->err_union = err_union; | 2398 | instruction->err_union_ptr = err_union_ptr; |
| 2378 | | 2399 | |
| 2379 | ir_ref_instruction(err_union, irb->current_basic_block); | 2400 | ir_ref_instruction(err_union_ptr, irb->current_basic_block); |
| 2380 | | 2401 | |
| 2381 | return &instruction->base; | 2402 | return &instruction->base; |
| 2382 | } | 2403 | } |
| ... | @@ -3505,7 +3526,8 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, | ... | @@ -3505,7 +3526,8 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3505 | | 3526 | |
| 3506 | ir_set_cursor_at_end_and_append_block(irb, return_block); | 3527 | ir_set_cursor_at_end_and_append_block(irb, return_block); |
| 3507 | if (!ir_gen_defers_for_block(irb, scope, outer_scope, true)) { | 3528 | if (!ir_gen_defers_for_block(irb, scope, outer_scope, true)) { |
| 3508 | IrInstruction *err_val = ir_build_unwrap_err_code(irb, scope, node, err_union_ptr); | 3529 | IrInstruction *err_val_ptr = ir_build_unwrap_err_code(irb, scope, node, err_union_ptr); |
| | 3530 | IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); |
| 3509 | if (irb->codegen->have_err_ret_tracing && !should_inline) { | 3531 | if (irb->codegen->have_err_ret_tracing && !should_inline) { |
| 3510 | ir_build_save_err_ret_addr(irb, scope, node); | 3532 | ir_build_save_err_ret_addr(irb, scope, node); |
| 3511 | } | 3533 | } |
| ... | @@ -5721,11 +5743,11 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5721,11 +5743,11 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5721 | | 5743 | |
| 5722 | ir_set_cursor_at_end_and_append_block(irb, body_block); | 5744 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 5723 | if (var_symbol) { | 5745 | if (var_symbol) { |
| 5724 | IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, payload_scope, symbol_node, | 5746 | IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, payload_scope, symbol_node, |
| 5725 | err_val_ptr, false); | 5747 | err_val_ptr, false); |
| 5726 | IrInstruction *var_value = node->data.while_expr.var_is_ptr ? | 5748 | IrInstruction *var_ptr = node->data.while_expr.var_is_ptr ? |
| 5727 | var_ptr_value : ir_build_load_ptr(irb, payload_scope, symbol_node, var_ptr_value); | 5749 | ir_build_ref(irb, payload_scope, symbol_node, payload_ptr, true, false) : payload_ptr; |
| 5728 | ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, var_value); | 5750 | ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, var_ptr); |
| 5729 | } | 5751 | } |
| 5730 | | 5752 | |
| 5731 | ZigList<IrInstruction *> incoming_values = {0}; | 5753 | ZigList<IrInstruction *> incoming_values = {0}; |
| ... | @@ -5766,8 +5788,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5766,8 +5788,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5766 | ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol, | 5788 | ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol, |
| 5767 | true, false, false, is_comptime); | 5789 | true, false, false, is_comptime); |
| 5768 | Scope *err_scope = err_var->child_scope; | 5790 | Scope *err_scope = err_var->child_scope; |
| 5769 | IrInstruction *err_var_value = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr); | 5791 | IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr); |
| 5770 | ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, err_var_value); | 5792 | ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, err_ptr); |
| 5771 | | 5793 | |
| 5772 | IrInstruction *else_result = ir_gen_node(irb, else_node, err_scope); | 5794 | IrInstruction *else_result = ir_gen_node(irb, else_node, err_scope); |
| 5773 | if (else_result == irb->codegen->invalid_instruction) | 5795 | if (else_result == irb->codegen->invalid_instruction) |
| ... | @@ -5808,10 +5830,10 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5808,10 +5830,10 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5808 | } | 5830 | } |
| 5809 | | 5831 | |
| 5810 | ir_set_cursor_at_end_and_append_block(irb, body_block); | 5832 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 5811 | IrInstruction *var_ptr_value = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false); | 5833 | IrInstruction *payload_ptr = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false); |
| 5812 | IrInstruction *var_value = node->data.while_expr.var_is_ptr ? | 5834 | IrInstruction *var_ptr = node->data.while_expr.var_is_ptr ? |
| 5813 | var_ptr_value : ir_build_load_ptr(irb, child_scope, symbol_node, var_ptr_value); | 5835 | ir_build_ref(irb, child_scope, symbol_node, payload_ptr, true, false) : payload_ptr; |
| 5814 | ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, var_value); | 5836 | ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, var_ptr); |
| 5815 | | 5837 | |
| 5816 | ZigList<IrInstruction *> incoming_values = {0}; | 5838 | ZigList<IrInstruction *> incoming_values = {0}; |
| 5817 | ZigList<IrBasicBlock *> incoming_blocks = {0}; | 5839 | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| ... | @@ -5953,6 +5975,15 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -5953,6 +5975,15 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5953 | if (array_val_ptr == irb->codegen->invalid_instruction) | 5975 | if (array_val_ptr == irb->codegen->invalid_instruction) |
| 5954 | return array_val_ptr; | 5976 | return array_val_ptr; |
| 5955 | | 5977 | |
| | 5978 | IrInstruction *pointer_type = ir_build_to_ptr_type(irb, parent_scope, array_node, array_val_ptr); |
| | 5979 | |
| | 5980 | IrInstruction *elem_var_type; |
| | 5981 | if (node->data.for_expr.elem_is_ptr) { |
| | 5982 | elem_var_type = pointer_type; |
| | 5983 | } else { |
| | 5984 | elem_var_type = ir_build_ptr_type_child(irb, parent_scope, elem_node, pointer_type); |
| | 5985 | } |
| | 5986 | |
| 5956 | IrInstruction *is_comptime = ir_build_const_bool(irb, parent_scope, node, | 5987 | IrInstruction *is_comptime = ir_build_const_bool(irb, parent_scope, node, |
| 5957 | ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline); | 5988 | ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline); |
| 5958 | | 5989 | |
| ... | @@ -5961,8 +5992,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -5961,8 +5992,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5961 | ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime); | 5992 | ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime); |
| 5962 | Scope *child_scope = elem_var->child_scope; | 5993 | Scope *child_scope = elem_var->child_scope; |
| 5963 | | 5994 | |
| 5964 | IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node); | 5995 | IrInstruction *undef = ir_build_const_undefined(irb, parent_scope, elem_node); |
| 5965 | ir_build_var_decl_src(irb, child_scope, elem_node, elem_var, nullptr, undefined_value); | 5996 | IrInstruction *undef_elem_var_type = ir_build_implicit_cast(irb, parent_scope, elem_node, elem_var_type, undef); |
| | 5997 | ir_build_var_decl_src(irb, child_scope, elem_node, elem_var, nullptr, undef_elem_var_type); |
| 5966 | IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var); | 5998 | IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var); |
| 5967 | | 5999 | |
| 5968 | AstNode *index_var_source_node; | 6000 | AstNode *index_var_source_node; |
| ... | @@ -6475,8 +6507,8 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -6475,8 +6507,8 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6475 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, | 6507 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| 6476 | err_symbol, is_const, is_const, is_shadowable, is_comptime); | 6508 | err_symbol, is_const, is_const, is_shadowable, is_comptime); |
| 6477 | | 6509 | |
| 6478 | IrInstruction *var_value = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr); | 6510 | IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr); |
| 6479 | ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_value); | 6511 | ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, err_ptr); |
| 6480 | err_var_scope = var->child_scope; | 6512 | err_var_scope = var->child_scope; |
| 6481 | } else { | 6513 | } else { |
| 6482 | err_var_scope = subexpr_scope; | 6514 | err_var_scope = subexpr_scope; |
| ... | @@ -7004,8 +7036,8 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -7004,8 +7036,8 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 7004 | ZigVar *var = ir_create_var(irb, node, parent_scope, var_name, | 7036 | ZigVar *var = ir_create_var(irb, node, parent_scope, var_name, |
| 7005 | is_const, is_const, is_shadowable, is_comptime); | 7037 | is_const, is_const, is_shadowable, is_comptime); |
| 7006 | err_scope = var->child_scope; | 7038 | err_scope = var->child_scope; |
| 7007 | IrInstruction *err_val = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr); | 7039 | IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr); |
| 7008 | ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_val); | 7040 | ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_ptr); |
| 7009 | } else { | 7041 | } else { |
| 7010 | err_scope = parent_scope; | 7042 | err_scope = parent_scope; |
| 7011 | } | 7043 | } |
| ... | @@ -7482,7 +7514,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -7482,7 +7514,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7482 | | 7514 | |
| 7483 | IrInstruction *promise_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_promise); | 7515 | IrInstruction *promise_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_promise); |
| 7484 | IrInstruction *const_bool_false = ir_build_const_bool(irb, scope, node, false); | 7516 | IrInstruction *const_bool_false = ir_build_const_bool(irb, scope, node, false); |
| 7485 | IrInstruction *undefined_value = ir_build_const_undefined(irb, scope, node); | 7517 | IrInstruction *undef = ir_build_const_undefined(irb, scope, node); |
| 7486 | IrInstruction *usize_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_usize); | 7518 | IrInstruction *usize_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_usize); |
| 7487 | IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0); | 7519 | IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0); |
| 7488 | IrInstruction *inverted_ptr_mask = ir_build_const_usize(irb, scope, node, 0x7); // 0b111 | 7520 | IrInstruction *inverted_ptr_mask = ir_build_const_usize(irb, scope, node, 0x7); // 0b111 |
| ... | @@ -7496,7 +7528,8 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -7496,7 +7528,8 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7496 | IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst); | 7528 | IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst); |
| 7497 | IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type); | 7529 | IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type); |
| 7498 | ir_build_await_bookkeeping(irb, scope, node, promise_result_type); | 7530 | ir_build_await_bookkeeping(irb, scope, node, promise_result_type); |
| 7499 | ir_build_var_decl_src(irb, scope, node, result_var, nullptr, undefined_value); | 7531 | IrInstruction *undef_promise_result = ir_build_implicit_cast(irb, scope, node, promise_result_type, undef); |
| | 7532 | ir_build_var_decl_src(irb, scope, node, result_var, nullptr, undef_promise_result); |
| 7500 | IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, scope, node, result_var); | 7533 | IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, scope, node, result_var); |
| 7501 | ir_build_store_ptr(irb, scope, node, result_ptr_field_ptr, my_result_var_ptr); | 7534 | ir_build_store_ptr(irb, scope, node, result_ptr_field_ptr, my_result_var_ptr); |
| 7502 | IrInstruction *save_token = ir_build_coro_save(irb, scope, node, irb->exec->coro_handle); | 7535 | IrInstruction *save_token = ir_build_coro_save(irb, scope, node, irb->exec->coro_handle); |
| ... | @@ -7928,12 +7961,18 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -7928,12 +7961,18 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 7928 | return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type; | 7961 | return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type; |
| 7929 | IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node); | 7962 | IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node); |
| 7930 | // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa | 7963 | // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa |
| 7931 | ir_build_var_decl_src(irb, coro_scope, node, promise_var, nullptr, undef); | 7964 | ZigType *coro_frame_type = get_promise_frame_type(irb->codegen, return_type); |
| | 7965 | IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type); |
| | 7966 | IrInstruction *undef_coro_frame = ir_build_implicit_cast(irb, coro_scope, node, coro_frame_type_value, undef); |
| | 7967 | ir_build_var_decl_src(irb, coro_scope, node, promise_var, nullptr, undef_coro_frame); |
| 7932 | coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var); | 7968 | coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var); |
| 7933 | | 7969 | |
| 7934 | ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); | 7970 | ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); |
| 7935 | IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node); | 7971 | IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node); |
| 7936 | ir_build_var_decl_src(irb, coro_scope, node, await_handle_var, nullptr, null_value); | 7972 | IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node, |
| | 7973 | get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise)); |
| | 7974 | IrInstruction *null_await_handle = ir_build_implicit_cast(irb, coro_scope, node, await_handle_type_val, null_value); |
| | 7975 | ir_build_var_decl_src(irb, coro_scope, node, await_handle_var, nullptr, null_await_handle); |
| 7937 | irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var); | 7976 | irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var); |
| 7938 | | 7977 | |
| 7939 | u8_ptr_type = ir_build_const_type(irb, coro_scope, node, | 7978 | u8_ptr_type = ir_build_const_type(irb, coro_scope, node, |
| ... | @@ -13872,7 +13911,8 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, | ... | @@ -13872,7 +13911,8 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 13872 | return ira->codegen->invalid_instruction; | 13911 | return ira->codegen->invalid_instruction; |
| 13873 | } | 13912 | } |
| 13874 | | 13913 | |
| 13875 | assert(var_ptr->value.type->id == ZigTypeIdPointer); | 13914 | // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value. |
| | 13915 | ir_assert(var_ptr->value.type->id == ZigTypeIdPointer, &decl_var_instruction->base); |
| 13876 | | 13916 | |
| 13877 | ZigType *result_type = var_ptr->value.type->data.pointer.child_type; | 13917 | ZigType *result_type = var_ptr->value.type->data.pointer.child_type; |
| 13878 | if (type_is_invalid(result_type)) { | 13918 | if (type_is_invalid(result_type)) { |
| ... | @@ -21526,13 +21566,14 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct | ... | @@ -21526,13 +21566,14 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct |
| 21526 | } | 21566 | } |
| 21527 | | 21567 | |
| 21528 | static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstructionUnwrapErrCode *instruction) { | 21568 | static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstructionUnwrapErrCode *instruction) { |
| 21529 | IrInstruction *base_ptr = instruction->err_union->child; | 21569 | IrInstruction *base_ptr = instruction->err_union_ptr->child; |
| 21530 | if (type_is_invalid(base_ptr->value.type)) | 21570 | if (type_is_invalid(base_ptr->value.type)) |
| 21531 | return ira->codegen->invalid_instruction; | 21571 | return ira->codegen->invalid_instruction; |
| 21532 | ZigType *ptr_type = base_ptr->value.type; | 21572 | ZigType *ptr_type = base_ptr->value.type; |
| 21533 | | 21573 | |
| 21534 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. | 21574 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| 21535 | assert(ptr_type->id == ZigTypeIdPointer); | 21575 | assert(ptr_type->id == ZigTypeIdPointer); |
| | 21576 | bool is_ptr_const = ptr_type->data.pointer.is_const; |
| 21536 | | 21577 | |
| 21537 | ZigType *type_entry = ptr_type->data.pointer.child_type; | 21578 | ZigType *type_entry = ptr_type->data.pointer.child_type; |
| 21538 | if (type_is_invalid(type_entry)) | 21579 | if (type_is_invalid(type_entry)) |
| ... | @@ -21554,19 +21595,22 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrI | ... | @@ -21554,19 +21595,22 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrI |
| 21554 | return ira->codegen->invalid_instruction; | 21595 | return ira->codegen->invalid_instruction; |
| 21555 | if (err_union_val->special != ConstValSpecialRuntime) { | 21596 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 21556 | ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set; | 21597 | ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set; |
| 21557 | assert(err); | 21598 | assert(err != nullptr); |
| 21558 | | 21599 | |
| 21559 | IrInstruction *result = ir_const(ira, &instruction->base, | 21600 | IrInstruction *err_set_val = ir_const(ira, &instruction->base, |
| 21560 | type_entry->data.error_union.err_set_type); | 21601 | type_entry->data.error_union.err_set_type); |
| 21561 | result->value.data.x_err_set = err; | 21602 | err_set_val->value.data.x_err_set = err; |
| 21562 | return result; | 21603 | err_set_val->value.parent.id = ConstParentIdErrUnionCode; |
| | 21604 | err_set_val->value.parent.data.p_err_union_code.err_union_val = err_union_val; |
| | 21605 | |
| | 21606 | return ir_get_ref(ira, &instruction->base, err_set_val, is_ptr_const, false); |
| 21563 | } | 21607 | } |
| 21564 | } | 21608 | } |
| 21565 | } | 21609 | } |
| 21566 | | 21610 | |
| 21567 | IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb, | 21611 | IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb, |
| 21568 | instruction->base.scope, instruction->base.source_node, base_ptr); | 21612 | instruction->base.scope, instruction->base.source_node, base_ptr); |
| 21569 | result->value.type = type_entry->data.error_union.err_set_type; | 21613 | result->value.type = get_pointer_to_type(ira->codegen, type_entry->data.error_union.err_set_type, is_ptr_const); |
| 21570 | return result; | 21614 | return result; |
| 21571 | } | 21615 | } |
| 21572 | | 21616 | |