| ... | ... | @@ -198,7 +198,7 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 198 | 198 | static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr, |
| 199 | 199 | IrInstruction *base_ptr, bool initializing); |
| 200 | 200 | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 201 | | IrInstruction *ptr, IrInstruction *uncasted_value); |
| 201 | IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const); |
| 202 | 202 | static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 203 | 203 | IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node, |
| 204 | 204 | LVal lval, ResultLoc *parent_result_loc); |
| ... | ... | @@ -1613,7 +1613,7 @@ static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode |
| 1613 | 1613 | return &unreachable_instruction->base; |
| 1614 | 1614 | } |
| 1615 | 1615 | |
| 1616 | | static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1616 | static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1617 | 1617 | IrInstruction *ptr, IrInstruction *value) |
| 1618 | 1618 | { |
| 1619 | 1619 | IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node); |
| ... | ... | @@ -1625,7 +1625,7 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode * |
| 1625 | 1625 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 1626 | 1626 | ir_ref_instruction(value, irb->current_basic_block); |
| 1627 | 1627 | |
| 1628 | | return &instruction->base; |
| 1628 | return instruction; |
| 1629 | 1629 | } |
| 1630 | 1630 | |
| 1631 | 1631 | static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| ... | ... | @@ -6051,6 +6051,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6051 | 6051 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| 6052 | 6052 | result_loc_inst->base.id = ResultLocIdInstruction; |
| 6053 | 6053 | result_loc_inst->base.source_instruction = field_ptr; |
| 6054 | result_loc_inst->base.allow_write_through_const = true; |
| 6054 | 6055 | ir_ref_instruction(field_ptr, irb->current_basic_block); |
| 6055 | 6056 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); |
| 6056 | 6057 | |
| ... | ... | @@ -6089,6 +6090,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6089 | 6090 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| 6090 | 6091 | result_loc_inst->base.id = ResultLocIdInstruction; |
| 6091 | 6092 | result_loc_inst->base.source_instruction = elem_ptr; |
| 6093 | result_loc_inst->base.allow_write_through_const = true; |
| 6092 | 6094 | ir_ref_instruction(elem_ptr, irb->current_basic_block); |
| 6093 | 6095 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); |
| 6094 | 6096 | |
| ... | ... | @@ -6646,7 +6648,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 6646 | 6648 | |
| 6647 | 6649 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| 6648 | 6650 | IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false); |
| 6649 | | ir_mark_gen(ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)); |
| 6651 | ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)->allow_write_through_const = true; |
| 6650 | 6652 | ir_build_br(irb, child_scope, node, cond_block, is_comptime); |
| 6651 | 6653 | |
| 6652 | 6654 | IrInstruction *else_result = nullptr; |
| ... | ... | @@ -14848,7 +14850,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 14848 | 14850 | // instruction. |
| 14849 | 14851 | assert(deref->value.special != ConstValSpecialRuntime); |
| 14850 | 14852 | var_ptr->value.special = ConstValSpecialRuntime; |
| 14851 | | ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref); |
| 14853 | ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false); |
| 14852 | 14854 | } |
| 14853 | 14855 | |
| 14854 | 14856 | if (var_ptr->value.special == ConstValSpecialStatic && var->mem_slot_index != SIZE_MAX) { |
| ... | ... | @@ -15862,7 +15864,7 @@ no_mem_slot: |
| 15862 | 15864 | } |
| 15863 | 15865 | |
| 15864 | 15866 | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 15865 | | IrInstruction *ptr, IrInstruction *uncasted_value) |
| 15867 | IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const) |
| 15866 | 15868 | { |
| 15867 | 15869 | assert(ptr->value.type->id == ZigTypeIdPointer); |
| 15868 | 15870 | |
| ... | ... | @@ -15878,7 +15880,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 15878 | 15880 | |
| 15879 | 15881 | ZigType *child_type = ptr->value.type->data.pointer.child_type; |
| 15880 | 15882 | |
| 15881 | | if (ptr->value.type->data.pointer.is_const && !source_instr->is_gen) { |
| 15883 | if (ptr->value.type->data.pointer.is_const && !allow_write_through_const) { |
| 15882 | 15884 | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 15883 | 15885 | return ira->codegen->invalid_instruction; |
| 15884 | 15886 | } |
| ... | ... | @@ -15957,10 +15959,9 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 15957 | 15959 | break; |
| 15958 | 15960 | } |
| 15959 | 15961 | |
| 15960 | | IrInstruction *result = ir_build_store_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, |
| 15961 | | ptr, value); |
| 15962 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 15963 | | return result; |
| 15962 | IrInstructionStorePtr *store_ptr = ir_build_store_ptr(&ira->new_irb, source_instr->scope, |
| 15963 | source_instr->source_node, ptr, value); |
| 15964 | return &store_ptr->base; |
| 15964 | 15965 | } |
| 15965 | 15966 | |
| 15966 | 15967 | static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, |
| ... | ... | @@ -18283,7 +18284,7 @@ static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstruc |
| 18283 | 18284 | if (type_is_invalid(value->value.type)) |
| 18284 | 18285 | return ira->codegen->invalid_instruction; |
| 18285 | 18286 | |
| 18286 | | return ir_analyze_store_ptr(ira, &instruction->base, ptr, value); |
| 18287 | return ir_analyze_store_ptr(ira, &instruction->base, ptr, value, instruction->allow_write_through_const); |
| 18287 | 18288 | } |
| 18288 | 18289 | |
| 18289 | 18290 | static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) { |
| ... | ... | @@ -19691,7 +19692,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 19691 | 19692 | |
| 19692 | 19693 | IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc, |
| 19693 | 19694 | container_type, true); |
| 19694 | | ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst); |
| 19695 | ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst, false); |
| 19695 | 19696 | if (instr_is_comptime(field_ptr) && field_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 19696 | 19697 | const_ptrs.append(field_ptr); |
| 19697 | 19698 | } else { |
| ... | ... | @@ -19708,7 +19709,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 19708 | 19709 | IrInstruction *field_result_loc = const_ptrs.at(i); |
| 19709 | 19710 | IrInstruction *deref = ir_get_deref(ira, field_result_loc, field_result_loc, nullptr); |
| 19710 | 19711 | field_result_loc->value.special = ConstValSpecialRuntime; |
| 19711 | | ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref); |
| 19712 | ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref, false); |
| 19712 | 19713 | } |
| 19713 | 19714 | } |
| 19714 | 19715 | } |
| ... | ... | @@ -19835,7 +19836,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 19835 | 19836 | assert(elem_result_loc->value.special == ConstValSpecialStatic); |
| 19836 | 19837 | IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr); |
| 19837 | 19838 | elem_result_loc->value.special = ConstValSpecialRuntime; |
| 19838 | | ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref); |
| 19839 | ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false); |
| 19839 | 19840 | } |
| 19840 | 19841 | } |
| 19841 | 19842 | } |
| ... | ... | @@ -25418,7 +25419,8 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 25418 | 25419 | return result_loc; |
| 25419 | 25420 | |
| 25420 | 25421 | if (!was_written) { |
| 25421 | | IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value); |
| 25422 | IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value, |
| 25423 | instruction->result_loc->allow_write_through_const); |
| 25422 | 25424 | if (type_is_invalid(store_ptr->value.type)) { |
| 25423 | 25425 | return ira->codegen->invalid_instruction; |
| 25424 | 25426 | } |