| ... | @@ -188,7 +188,8 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -188,7 +188,8 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 188 | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, | 188 | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 189 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime); | 189 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime); |
| 190 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, | 190 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 191 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime); | 191 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, |
| | 192 | bool non_null_comptime, bool allow_discard); |
| 192 | static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr, | 193 | static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 193 | IrInstruction *base_ptr, bool safety_check_on, bool initializing); | 194 | IrInstruction *base_ptr, bool safety_check_on, bool initializing); |
| 194 | static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr, | 195 | static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| ... | @@ -196,7 +197,7 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct | ... | @@ -196,7 +197,7 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 196 | static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr, | 197 | static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr, |
| 197 | IrInstruction *base_ptr, bool initializing); | 198 | IrInstruction *base_ptr, bool initializing); |
| 198 | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, | 199 | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 199 | IrInstruction *ptr, IrInstruction *uncasted_value); | 200 | IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const); |
| 200 | static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node, | 201 | static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 201 | IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node, | 202 | IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node, |
| 202 | LVal lval, ResultLoc *parent_result_loc); | 203 | LVal lval, ResultLoc *parent_result_loc); |
| ... | @@ -1564,7 +1565,7 @@ static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -1564,7 +1565,7 @@ static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode |
| 1564 | return &unreachable_instruction->base; | 1565 | return &unreachable_instruction->base; |
| 1565 | } | 1566 | } |
| 1566 | | 1567 | |
| 1567 | static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1568 | static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1568 | IrInstruction *ptr, IrInstruction *value) | 1569 | IrInstruction *ptr, IrInstruction *value) |
| 1569 | { | 1570 | { |
| 1570 | IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node); | 1571 | IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node); |
| ... | @@ -1576,7 +1577,7 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -1576,7 +1577,7 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode * |
| 1576 | ir_ref_instruction(ptr, irb->current_basic_block); | 1577 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 1577 | ir_ref_instruction(value, irb->current_basic_block); | 1578 | ir_ref_instruction(value, irb->current_basic_block); |
| 1578 | | 1579 | |
| 1579 | return &instruction->base; | 1580 | return instruction; |
| 1580 | } | 1581 | } |
| 1581 | | 1582 | |
| 1582 | static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1583 | static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| ... | @@ -3792,12 +3793,20 @@ static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *no | ... | @@ -3792,12 +3793,20 @@ static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *no |
| 3792 | | 3793 | |
| 3793 | static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) { | 3794 | static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 3794 | IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr); | 3795 | IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr); |
| 3795 | IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); | 3796 | if (lvalue == irb->codegen->invalid_instruction) |
| | 3797 | return irb->codegen->invalid_instruction; |
| | 3798 | |
| | 3799 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| | 3800 | result_loc_inst->base.id = ResultLocIdInstruction; |
| | 3801 | result_loc_inst->base.source_instruction = lvalue; |
| | 3802 | ir_ref_instruction(lvalue, irb->current_basic_block); |
| | 3803 | ir_build_reset_result(irb, scope, node, &result_loc_inst->base); |
| 3796 | | 3804 | |
| 3797 | if (lvalue == irb->codegen->invalid_instruction || rvalue == irb->codegen->invalid_instruction) | 3805 | IrInstruction *rvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op2, scope, LValNone, |
| | 3806 | &result_loc_inst->base); |
| | 3807 | if (rvalue == irb->codegen->invalid_instruction) |
| 3798 | return irb->codegen->invalid_instruction; | 3808 | return irb->codegen->invalid_instruction; |
| 3799 | | 3809 | |
| 3800 | ir_build_store_ptr(irb, scope, node, lvalue, rvalue); | | |
| 3801 | return ir_build_const_void(irb, scope, node); | 3810 | return ir_build_const_void(irb, scope, node); |
| 3802 | } | 3811 | } |
| 3803 | | 3812 | |
| ... | @@ -5836,6 +5845,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A | ... | @@ -5836,6 +5845,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 5836 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); | 5845 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| 5837 | result_loc_inst->base.id = ResultLocIdInstruction; | 5846 | result_loc_inst->base.id = ResultLocIdInstruction; |
| 5838 | result_loc_inst->base.source_instruction = field_ptr; | 5847 | result_loc_inst->base.source_instruction = field_ptr; |
| | 5848 | result_loc_inst->base.allow_write_through_const = true; |
| 5839 | ir_ref_instruction(field_ptr, irb->current_basic_block); | 5849 | ir_ref_instruction(field_ptr, irb->current_basic_block); |
| 5840 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); | 5850 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); |
| 5841 | | 5851 | |
| ... | @@ -5874,6 +5884,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A | ... | @@ -5874,6 +5884,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 5874 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); | 5884 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| 5875 | result_loc_inst->base.id = ResultLocIdInstruction; | 5885 | result_loc_inst->base.id = ResultLocIdInstruction; |
| 5876 | result_loc_inst->base.source_instruction = elem_ptr; | 5886 | result_loc_inst->base.source_instruction = elem_ptr; |
| | 5887 | result_loc_inst->base.allow_write_through_const = true; |
| 5877 | ir_ref_instruction(elem_ptr, irb->current_basic_block); | 5888 | ir_ref_instruction(elem_ptr, irb->current_basic_block); |
| 5878 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); | 5889 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); |
| 5879 | | 5890 | |
| ... | @@ -6431,7 +6442,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -6431,7 +6442,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 6431 | | 6442 | |
| 6432 | ir_set_cursor_at_end_and_append_block(irb, continue_block); | 6443 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| 6433 | IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false); | 6444 | IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false); |
| 6434 | ir_mark_gen(ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)); | 6445 | ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)->allow_write_through_const = true; |
| 6435 | ir_build_br(irb, child_scope, node, cond_block, is_comptime); | 6446 | ir_build_br(irb, child_scope, node, cond_block, is_comptime); |
| 6436 | | 6447 | |
| 6437 | IrInstruction *else_result = nullptr; | 6448 | IrInstruction *else_result = nullptr; |
| ... | @@ -10344,7 +10355,8 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc | ... | @@ -10344,7 +10355,8 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc |
| 10344 | } | 10355 | } |
| 10345 | | 10356 | |
| 10346 | if (result_loc == nullptr) result_loc = no_result_loc(); | 10357 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 10347 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false); | 10358 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, |
| | 10359 | false, true); |
| 10348 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 10360 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 10349 | return result_loc_inst; | 10361 | return result_loc_inst; |
| 10350 | } | 10362 | } |
| ... | @@ -10804,7 +10816,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so | ... | @@ -10804,7 +10816,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so |
| 10804 | } | 10816 | } |
| 10805 | IrInstruction *result_loc_inst = nullptr; | 10817 | IrInstruction *result_loc_inst = nullptr; |
| 10806 | if (result_loc != nullptr) { | 10818 | if (result_loc != nullptr) { |
| 10807 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false); | 10819 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); |
| 10808 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 10820 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 10809 | return result_loc_inst; | 10821 | return result_loc_inst; |
| 10810 | } | 10822 | } |
| ... | @@ -10847,7 +10859,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction | ... | @@ -10847,7 +10859,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 10847 | IrInstruction *result_loc_inst; | 10859 | IrInstruction *result_loc_inst; |
| 10848 | if (handle_is_ptr(wanted_type)) { | 10860 | if (handle_is_ptr(wanted_type)) { |
| 10849 | if (result_loc == nullptr) result_loc = no_result_loc(); | 10861 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 10850 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false); | 10862 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); |
| 10851 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 10863 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 10852 | return result_loc_inst; | 10864 | return result_loc_inst; |
| 10853 | } | 10865 | } |
| ... | @@ -10959,7 +10971,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so | ... | @@ -10959,7 +10971,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 10959 | IrInstruction *result_loc_inst; | 10971 | IrInstruction *result_loc_inst; |
| 10960 | if (handle_is_ptr(wanted_type)) { | 10972 | if (handle_is_ptr(wanted_type)) { |
| 10961 | if (result_loc == nullptr) result_loc = no_result_loc(); | 10973 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 10962 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false); | 10974 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); |
| 10963 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 10975 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 10964 | return result_loc_inst; | 10976 | return result_loc_inst; |
| 10965 | } | 10977 | } |
| ... | @@ -11032,7 +11044,8 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi | ... | @@ -11032,7 +11044,8 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 11032 | | 11044 | |
| 11033 | IrInstruction *result_loc; | 11045 | IrInstruction *result_loc; |
| 11034 | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value.type)) { | 11046 | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value.type)) { |
| 11035 | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr, true, false); | 11047 | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr, true, |
| | 11048 | false, true); |
| 11036 | } else { | 11049 | } else { |
| 11037 | result_loc = nullptr; | 11050 | result_loc = nullptr; |
| 11038 | } | 11051 | } |
| ... | @@ -11076,7 +11089,8 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s | ... | @@ -11076,7 +11089,8 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s |
| 11076 | if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false); | 11089 | if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false); |
| 11077 | | 11090 | |
| 11078 | if (result_loc == nullptr) result_loc = no_result_loc(); | 11091 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 11079 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false); | 11092 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, |
| | 11093 | true, false, true); |
| 11080 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 11094 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11081 | return result_loc_inst; | 11095 | return result_loc_inst; |
| 11082 | } | 11096 | } |
| ... | @@ -11732,7 +11746,8 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * | ... | @@ -11732,7 +11746,8 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * |
| 11732 | if (result_loc == nullptr) { | 11746 | if (result_loc == nullptr) { |
| 11733 | result_loc = no_result_loc(); | 11747 | result_loc = no_result_loc(); |
| 11734 | } | 11748 | } |
| 11735 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true, false); | 11749 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, |
| | 11750 | true, false, true); |
| 11736 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 11751 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11737 | return result_loc_inst; | 11752 | return result_loc_inst; |
| 11738 | } | 11753 | } |
| ... | @@ -12334,7 +12349,8 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc | ... | @@ -12334,7 +12349,8 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 12334 | IrInstruction *result_loc_inst; | 12349 | IrInstruction *result_loc_inst; |
| 12335 | if (type_entry->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) { | 12350 | if (type_entry->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) { |
| 12336 | if (result_loc == nullptr) result_loc = no_result_loc(); | 12351 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 12337 | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true, false); | 12352 | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, |
| | 12353 | true, false, true); |
| 12338 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | 12354 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 12339 | return result_loc_inst; | 12355 | return result_loc_inst; |
| 12340 | } | 12356 | } |
| ... | @@ -14072,7 +14088,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, | ... | @@ -14072,7 +14088,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 14072 | // instruction. | 14088 | // instruction. |
| 14073 | assert(deref->value.special != ConstValSpecialRuntime); | 14089 | assert(deref->value.special != ConstValSpecialRuntime); |
| 14074 | var_ptr->value.special = ConstValSpecialRuntime; | 14090 | var_ptr->value.special = ConstValSpecialRuntime; |
| 14075 | ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref); | 14091 | ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false); |
| 14076 | } | 14092 | } |
| 14077 | | 14093 | |
| 14078 | if (var_ptr->value.special == ConstValSpecialStatic && var->mem_slot_index != SIZE_MAX) { | 14094 | if (var_ptr->value.special == ConstValSpecialStatic && var->mem_slot_index != SIZE_MAX) { |
| ... | @@ -14556,7 +14572,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -14556,7 +14572,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 14556 | | 14572 | |
| 14557 | if (peer_parent->peers.length == 1) { | 14573 | if (peer_parent->peers.length == 1) { |
| 14558 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, | 14574 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 14559 | value_type, value, force_runtime, non_null_comptime); | 14575 | value_type, value, force_runtime, non_null_comptime, true); |
| 14560 | result_peer->suspend_pos.basic_block_index = SIZE_MAX; | 14576 | result_peer->suspend_pos.basic_block_index = SIZE_MAX; |
| 14561 | result_peer->suspend_pos.instruction_index = SIZE_MAX; | 14577 | result_peer->suspend_pos.instruction_index = SIZE_MAX; |
| 14562 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || | 14578 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| ... | @@ -14576,7 +14592,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -14576,7 +14592,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 14576 | if (peer_parent->skipped) { | 14592 | if (peer_parent->skipped) { |
| 14577 | if (non_null_comptime) { | 14593 | if (non_null_comptime) { |
| 14578 | return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, | 14594 | return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 14579 | value_type, value, force_runtime, non_null_comptime); | 14595 | value_type, value, force_runtime, non_null_comptime, true); |
| 14580 | } | 14596 | } |
| 14581 | return nullptr; | 14597 | return nullptr; |
| 14582 | } | 14598 | } |
| ... | @@ -14594,7 +14610,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -14594,7 +14610,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 14594 | } | 14610 | } |
| 14595 | | 14611 | |
| 14596 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, | 14612 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 14597 | peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime); | 14613 | peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true); |
| 14598 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || | 14614 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| 14599 | parent_result_loc->value.type->id == ZigTypeIdUnreachable) | 14615 | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| 14600 | { | 14616 | { |
| ... | @@ -14644,7 +14660,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -14644,7 +14660,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 14644 | } | 14660 | } |
| 14645 | | 14661 | |
| 14646 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, | 14662 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, |
| 14647 | dest_type, bitcasted_value, force_runtime, non_null_comptime); | 14663 | dest_type, bitcasted_value, force_runtime, non_null_comptime, true); |
| 14648 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || | 14664 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| 14649 | parent_result_loc->value.type->id == ZigTypeIdUnreachable) | 14665 | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| 14650 | { | 14666 | { |
| ... | @@ -14673,8 +14689,15 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -14673,8 +14689,15 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 14673 | | 14689 | |
| 14674 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, | 14690 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 14675 | ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime, | 14691 | ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime, |
| 14676 | bool non_null_comptime) | 14692 | bool non_null_comptime, bool allow_discard) |
| 14677 | { | 14693 | { |
| | 14694 | if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction && |
| | 14695 | instr_is_comptime(result_loc_pass1->source_instruction) && |
| | 14696 | result_loc_pass1->source_instruction->value.type->id == ZigTypeIdPointer && |
| | 14697 | result_loc_pass1->source_instruction->value.data.x_ptr.special == ConstPtrSpecialDiscard) |
| | 14698 | { |
| | 14699 | result_loc_pass1 = no_result_loc(); |
| | 14700 | } |
| 14678 | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, | 14701 | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, |
| 14679 | value, force_runtime, non_null_comptime); | 14702 | value, force_runtime, non_null_comptime); |
| 14680 | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value.type))) | 14703 | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value.type))) |
| ... | @@ -14729,7 +14752,7 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrIn | ... | @@ -14729,7 +14752,7 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrIn |
| 14729 | if (type_is_invalid(implicit_elem_type)) | 14752 | if (type_is_invalid(implicit_elem_type)) |
| 14730 | return ira->codegen->invalid_instruction; | 14753 | return ira->codegen->invalid_instruction; |
| 14731 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 14754 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 14732 | implicit_elem_type, nullptr, false, true); | 14755 | implicit_elem_type, nullptr, false, true, true); |
| 14733 | if (result_loc != nullptr) | 14756 | if (result_loc != nullptr) |
| 14734 | return result_loc; | 14757 | return result_loc; |
| 14735 | | 14758 | |
| ... | @@ -14738,7 +14761,7 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrIn | ... | @@ -14738,7 +14761,7 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrIn |
| 14738 | instruction->result_loc->id == ResultLocIdReturn) | 14761 | instruction->result_loc->id == ResultLocIdReturn) |
| 14739 | { | 14762 | { |
| 14740 | result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(), | 14763 | result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(), |
| 14741 | implicit_elem_type, nullptr, false, true); | 14764 | implicit_elem_type, nullptr, false, true, true); |
| 14742 | if (result_loc != nullptr && | 14765 | if (result_loc != nullptr && |
| 14743 | (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) | 14766 | (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) |
| 14744 | { | 14767 | { |
| ... | @@ -14800,7 +14823,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc | ... | @@ -14800,7 +14823,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc |
| 14800 | | 14823 | |
| 14801 | ZigType *frame_type = get_coro_frame_type(ira->codegen, fn_entry); | 14824 | ZigType *frame_type = get_coro_frame_type(ira->codegen, fn_entry); |
| 14802 | IrInstruction *result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, | 14825 | IrInstruction *result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 14803 | frame_type, nullptr, true, true); | 14826 | frame_type, nullptr, true, true, false); |
| 14804 | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) { | 14827 | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) { |
| 14805 | return result_loc; | 14828 | return result_loc; |
| 14806 | } | 14829 | } |
| ... | @@ -15015,7 +15038,7 @@ no_mem_slot: | ... | @@ -15015,7 +15038,7 @@ no_mem_slot: |
| 15015 | } | 15038 | } |
| 15016 | | 15039 | |
| 15017 | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, | 15040 | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 15018 | IrInstruction *ptr, IrInstruction *uncasted_value) | 15041 | IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const) |
| 15019 | { | 15042 | { |
| 15020 | assert(ptr->value.type->id == ZigTypeIdPointer); | 15043 | assert(ptr->value.type->id == ZigTypeIdPointer); |
| 15021 | | 15044 | |
| ... | @@ -15031,7 +15054,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source | ... | @@ -15031,7 +15054,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 15031 | | 15054 | |
| 15032 | ZigType *child_type = ptr->value.type->data.pointer.child_type; | 15055 | ZigType *child_type = ptr->value.type->data.pointer.child_type; |
| 15033 | | 15056 | |
| 15034 | if (ptr->value.type->data.pointer.is_const && !source_instr->is_gen) { | 15057 | if (ptr->value.type->data.pointer.is_const && !allow_write_through_const) { |
| 15035 | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); | 15058 | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 15036 | return ira->codegen->invalid_instruction; | 15059 | return ira->codegen->invalid_instruction; |
| 15037 | } | 15060 | } |
| ... | @@ -15110,10 +15133,9 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source | ... | @@ -15110,10 +15133,9 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 15110 | break; | 15133 | break; |
| 15111 | } | 15134 | } |
| 15112 | | 15135 | |
| 15113 | IrInstruction *result = ir_build_store_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, | 15136 | IrInstructionStorePtr *store_ptr = ir_build_store_ptr(&ira->new_irb, source_instr->scope, |
| 15114 | ptr, value); | 15137 | source_instr->source_node, ptr, value); |
| 15115 | result->value.type = ira->codegen->builtin_types.entry_void; | 15138 | return &store_ptr->base; |
| 15116 | return result; | | |
| 15117 | } | 15139 | } |
| 15118 | | 15140 | |
| 15119 | static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, | 15141 | static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, |
| ... | @@ -15518,7 +15540,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c | ... | @@ -15518,7 +15540,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 15518 | IrInstruction *result_loc; | 15540 | IrInstruction *result_loc; |
| 15519 | if (handle_is_ptr(impl_fn_type_id->return_type)) { | 15541 | if (handle_is_ptr(impl_fn_type_id->return_type)) { |
| 15520 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, | 15542 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 15521 | impl_fn_type_id->return_type, nullptr, true, true); | 15543 | impl_fn_type_id->return_type, nullptr, true, true, false); |
| 15522 | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || | 15544 | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || |
| 15523 | instr_is_unreachable(result_loc))) | 15545 | instr_is_unreachable(result_loc))) |
| 15524 | { | 15546 | { |
| ... | @@ -15635,7 +15657,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c | ... | @@ -15635,7 +15657,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 15635 | IrInstruction *result_loc; | 15657 | IrInstruction *result_loc; |
| 15636 | if (handle_is_ptr(return_type)) { | 15658 | if (handle_is_ptr(return_type)) { |
| 15637 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, | 15659 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 15638 | return_type, nullptr, true, true); | 15660 | return_type, nullptr, true, true, false); |
| 15639 | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) { | 15661 | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) { |
| 15640 | return result_loc; | 15662 | return result_loc; |
| 15641 | } | 15663 | } |
| ... | @@ -16154,7 +16176,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh | ... | @@ -16154,7 +16176,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 16154 | | 16176 | |
| 16155 | // In case resolving the parent activates a suspend, do it now | 16177 | // In case resolving the parent activates a suspend, do it now |
| 16156 | IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent, | 16178 | IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent, |
| 16157 | peer_parent->resolved_type, nullptr, false, false); | 16179 | peer_parent->resolved_type, nullptr, false, false, true); |
| 16158 | if (parent_result_loc != nullptr && | 16180 | if (parent_result_loc != nullptr && |
| 16159 | (type_is_invalid(parent_result_loc->value.type) || instr_is_unreachable(parent_result_loc))) | 16181 | (type_is_invalid(parent_result_loc->value.type) || instr_is_unreachable(parent_result_loc))) |
| 16160 | { | 16182 | { |
| ... | @@ -16611,6 +16633,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct | ... | @@ -16611,6 +16633,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 16611 | return result; | 16633 | return result; |
| 16612 | } else if (is_slice(array_type)) { | 16634 | } else if (is_slice(array_type)) { |
| 16613 | ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index]; | 16635 | ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index]; |
| | 16636 | ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base); |
| 16614 | if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { | 16637 | if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 16615 | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, | 16638 | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, |
| 16616 | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false, | 16639 | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false, |
| ... | @@ -16797,7 +16820,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction | ... | @@ -16797,7 +16820,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 16797 | return ira->codegen->invalid_instruction; | 16820 | return ira->codegen->invalid_instruction; |
| 16798 | if (type_is_invalid(struct_val->type)) | 16821 | if (type_is_invalid(struct_val->type)) |
| 16799 | return ira->codegen->invalid_instruction; | 16822 | return ira->codegen->invalid_instruction; |
| 16800 | if (struct_val->special == ConstValSpecialUndef && initializing) { | 16823 | if (initializing && struct_val->special == ConstValSpecialUndef) { |
| 16801 | struct_val->data.x_struct.fields = create_const_vals(struct_type->data.structure.src_field_count); | 16824 | struct_val->data.x_struct.fields = create_const_vals(struct_type->data.structure.src_field_count); |
| 16802 | struct_val->special = ConstValSpecialStatic; | 16825 | struct_val->special = ConstValSpecialStatic; |
| 16803 | for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) { | 16826 | for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) { |
| ... | @@ -17395,7 +17418,7 @@ static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -17395,7 +17418,7 @@ static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstruc |
| 17395 | if (type_is_invalid(value->value.type)) | 17418 | if (type_is_invalid(value->value.type)) |
| 17396 | return ira->codegen->invalid_instruction; | 17419 | return ira->codegen->invalid_instruction; |
| 17397 | | 17420 | |
| 17398 | return ir_analyze_store_ptr(ira, &instruction->base, ptr, value); | 17421 | return ir_analyze_store_ptr(ira, &instruction->base, ptr, value, instruction->allow_write_through_const); |
| 17399 | } | 17422 | } |
| 17400 | | 17423 | |
| 17401 | static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) { | 17424 | static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) { |
| ... | @@ -17899,7 +17922,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr | ... | @@ -17899,7 +17922,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 17899 | if (optional_val == nullptr) | 17922 | if (optional_val == nullptr) |
| 17900 | return ira->codegen->invalid_instruction; | 17923 | return ira->codegen->invalid_instruction; |
| 17901 | | 17924 | |
| 17902 | if (initializing && optional_val->special == ConstValSpecialUndef) { | 17925 | if (initializing) { |
| 17903 | switch (type_has_one_possible_value(ira->codegen, child_type)) { | 17926 | switch (type_has_one_possible_value(ira->codegen, child_type)) { |
| 17904 | case OnePossibleValueInvalid: | 17927 | case OnePossibleValueInvalid: |
| 17905 | return ira->codegen->invalid_instruction; | 17928 | return ira->codegen->invalid_instruction; |
| ... | @@ -18805,7 +18828,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc | ... | @@ -18805,7 +18828,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 18805 | | 18828 | |
| 18806 | IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc, | 18829 | IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc, |
| 18807 | container_type, true); | 18830 | container_type, true); |
| 18808 | ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst); | 18831 | ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst, false); |
| 18809 | if (instr_is_comptime(field_ptr) && field_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { | 18832 | if (instr_is_comptime(field_ptr) && field_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 18810 | const_ptrs.append(field_ptr); | 18833 | const_ptrs.append(field_ptr); |
| 18811 | } else { | 18834 | } else { |
| ... | @@ -18822,7 +18845,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc | ... | @@ -18822,7 +18845,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 18822 | IrInstruction *field_result_loc = const_ptrs.at(i); | 18845 | IrInstruction *field_result_loc = const_ptrs.at(i); |
| 18823 | IrInstruction *deref = ir_get_deref(ira, field_result_loc, field_result_loc, nullptr); | 18846 | IrInstruction *deref = ir_get_deref(ira, field_result_loc, field_result_loc, nullptr); |
| 18824 | field_result_loc->value.special = ConstValSpecialRuntime; | 18847 | field_result_loc->value.special = ConstValSpecialRuntime; |
| 18825 | ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref); | 18848 | ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref, false); |
| 18826 | } | 18849 | } |
| 18827 | } | 18850 | } |
| 18828 | } | 18851 | } |
| ... | @@ -18949,7 +18972,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, | ... | @@ -18949,7 +18972,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 18949 | assert(elem_result_loc->value.special == ConstValSpecialStatic); | 18972 | assert(elem_result_loc->value.special == ConstValSpecialStatic); |
| 18950 | IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr); | 18973 | IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr); |
| 18951 | elem_result_loc->value.special = ConstValSpecialRuntime; | 18974 | elem_result_loc->value.special = ConstValSpecialRuntime; |
| 18952 | ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref); | 18975 | ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false); |
| 18953 | } | 18976 | } |
| 18954 | } | 18977 | } |
| 18955 | } | 18978 | } |
| ... | @@ -20646,7 +20669,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi | ... | @@ -20646,7 +20669,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 20646 | IrInstruction *result_loc; | 20669 | IrInstruction *result_loc; |
| 20647 | if (handle_is_ptr(result_type)) { | 20670 | if (handle_is_ptr(result_type)) { |
| 20648 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 20671 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 20649 | result_type, nullptr, true, false); | 20672 | result_type, nullptr, true, false, true); |
| 20650 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { | 20673 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 20651 | return result_loc; | 20674 | return result_loc; |
| 20652 | } | 20675 | } |
| ... | @@ -20903,7 +20926,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru | ... | @@ -20903,7 +20926,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 20903 | } | 20926 | } |
| 20904 | | 20927 | |
| 20905 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 20928 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 20906 | dest_slice_type, nullptr, true, false); | 20929 | dest_slice_type, nullptr, true, false, true); |
| 20907 | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) { | 20930 | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) { |
| 20908 | return result_loc; | 20931 | return result_loc; |
| 20909 | } | 20932 | } |
| ... | @@ -20980,7 +21003,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct | ... | @@ -20980,7 +21003,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 20980 | } | 21003 | } |
| 20981 | | 21004 | |
| 20982 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 21005 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 20983 | dest_slice_type, nullptr, true, false); | 21006 | dest_slice_type, nullptr, true, false, true); |
| 20984 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { | 21007 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 20985 | return result_loc; | 21008 | return result_loc; |
| 20986 | } | 21009 | } |
| ... | @@ -21722,7 +21745,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction | ... | @@ -21722,7 +21745,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 21722 | } | 21745 | } |
| 21723 | | 21746 | |
| 21724 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 21747 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 21725 | return_type, nullptr, true, false); | 21748 | return_type, nullptr, true, false, true); |
| 21726 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { | 21749 | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 21727 | return result_loc; | 21750 | return result_loc; |
| 21728 | } | 21751 | } |
| ... | @@ -22405,7 +22428,7 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct | ... | @@ -22405,7 +22428,7 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 22405 | ConstExprValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); | 22428 | ConstExprValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 22406 | if (err_union_val == nullptr) | 22429 | if (err_union_val == nullptr) |
| 22407 | return ira->codegen->invalid_instruction; | 22430 | return ira->codegen->invalid_instruction; |
| 22408 | if (err_union_val->special == ConstValSpecialUndef && initializing) { | 22431 | if (initializing && err_union_val->special == ConstValSpecialUndef) { |
| 22409 | ConstExprValue *vals = create_const_vals(2); | 22432 | ConstExprValue *vals = create_const_vals(2); |
| 22410 | ConstExprValue *err_set_val = &vals[0]; | 22433 | ConstExprValue *err_set_val = &vals[0]; |
| 22411 | ConstExprValue *payload_val = &vals[1]; | 22434 | ConstExprValue *payload_val = &vals[1]; |
| ... | @@ -23700,10 +23723,11 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op | ... | @@ -23700,10 +23723,11 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op |
| 23700 | operand_type->data.integral.bit_count)); | 23723 | operand_type->data.integral.bit_count)); |
| 23701 | return ira->codegen->builtin_types.entry_invalid; | 23724 | return ira->codegen->builtin_types.entry_invalid; |
| 23702 | } | 23725 | } |
| 23703 | if (operand_type->data.integral.bit_count > ira->codegen->pointer_size_bytes * 8) { | 23726 | uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch); |
| | 23727 | if (operand_type->data.integral.bit_count > max_atomic_bits) { |
| 23704 | ir_add_error(ira, op, | 23728 | ir_add_error(ira, op, |
| 23705 | buf_sprintf("expected integer type pointer size or smaller, found %" PRIu32 "-bit integer type", | 23729 | buf_sprintf("expected %" PRIu32 "-bit integer type or smaller, found %" PRIu32 "-bit integer type", |
| 23706 | operand_type->data.integral.bit_count)); | 23730 | max_atomic_bits, operand_type->data.integral.bit_count)); |
| 23707 | return ira->codegen->builtin_types.entry_invalid; | 23731 | return ira->codegen->builtin_types.entry_invalid; |
| 23708 | } | 23732 | } |
| 23709 | if (!is_power_of_2(operand_type->data.integral.bit_count)) { | 23733 | if (!is_power_of_2(operand_type->data.integral.bit_count)) { |
| ... | @@ -24293,7 +24317,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct | ... | @@ -24293,7 +24317,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 24293 | | 24317 | |
| 24294 | bool was_written = instruction->result_loc->written; | 24318 | bool was_written = instruction->result_loc->written; |
| 24295 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, | 24319 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 24296 | value->value.type, value, false, false); | 24320 | value->value.type, value, false, false, true); |
| 24297 | if (result_loc != nullptr) { | 24321 | if (result_loc != nullptr) { |
| 24298 | if (type_is_invalid(result_loc->value.type)) | 24322 | if (type_is_invalid(result_loc->value.type)) |
| 24299 | return ira->codegen->invalid_instruction; | 24323 | return ira->codegen->invalid_instruction; |
| ... | @@ -24301,7 +24325,8 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct | ... | @@ -24301,7 +24325,8 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 24301 | return result_loc; | 24325 | return result_loc; |
| 24302 | | 24326 | |
| 24303 | if (!was_written) { | 24327 | if (!was_written) { |
| 24304 | IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value); | 24328 | IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value, |
| | 24329 | instruction->result_loc->allow_write_through_const); |
| 24305 | if (type_is_invalid(store_ptr->value.type)) { | 24330 | if (type_is_invalid(store_ptr->value.type)) { |
| 24306 | return ira->codegen->invalid_instruction; | 24331 | return ira->codegen->invalid_instruction; |
| 24307 | } | 24332 | } |
| ... | @@ -24325,7 +24350,7 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst | ... | @@ -24325,7 +24350,7 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst |
| 24325 | return operand; | 24350 | return operand; |
| 24326 | | 24351 | |
| 24327 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, | 24352 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, |
| 24328 | &instruction->result_loc_bit_cast->base, operand->value.type, operand, false, false); | 24353 | &instruction->result_loc_bit_cast->base, operand->value.type, operand, false, false, true); |
| 24329 | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) | 24354 | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) |
| 24330 | return result_loc; | 24355 | return result_loc; |
| 24331 | | 24356 | |