authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-04-08 14:20:05+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-04-08 14:32:02+03:00
logb1e44adcba55e3839a3676db83ff61c344f3bbad
treecc2541bfa61def94dba357e08e29310da3cdb39f
parentff0f97a1bcab4d27212c67b0ebc6233adf2f0de9
signaturelock-open Commit is signed but in an unrecognized format.

move array and struct const checks to more appropriate places


2 files changed, 15 insertions(+), 16 deletions(-)

src/ir.cpp+13-14
...@@ -23552,10 +23552,14 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -23552,10 +23552,14 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
23552 IrInstGen *result_loc = instruction->result_loc->child;23552 IrInstGen *result_loc = instruction->result_loc->child;
23553 if (type_is_invalid(result_loc->value->type))23553 if (type_is_invalid(result_loc->value->type))
23554 return result_loc;23554 return result_loc;
23555
23555 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);23556 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);
23557 if (result_loc->value->type->data.pointer.is_const) {
23558 ir_add_error(ira, &instruction->base.base, buf_sprintf("cannot assign to constant"));
23559 return ira->codegen->invalid_inst_gen;
23560 }
2355623561
23557 ZigType *container_type = result_loc->value->type->data.pointer.child_type;23562 ZigType *container_type = result_loc->value->type->data.pointer.child_type;
23558
23559 size_t elem_count = instruction->item_count;23563 size_t elem_count = instruction->item_count;
2356023564
23561 if (is_slice(container_type)) {23565 if (is_slice(container_type)) {
...@@ -23706,6 +23710,11 @@ static IrInstGen *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,...@@ -23706,6 +23710,11 @@ static IrInstGen *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,
23706 return result_loc;23710 return result_loc;
2370723711
23708 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);23712 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);
23713 if (result_loc->value->type->data.pointer.is_const) {
23714 ir_add_error(ira, &instruction->base.base, buf_sprintf("cannot assign to constant"));
23715 return ira->codegen->invalid_inst_gen;
23716 }
23717
23709 ZigType *container_type = result_loc->value->type->data.pointer.child_type;23718 ZigType *container_type = result_loc->value->type->data.pointer.child_type;
2371023719
23711 return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type,23720 return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type,
...@@ -27176,11 +27185,8 @@ done_with_return_type:...@@ -27176,11 +27185,8 @@ done_with_return_type:
27176 return result_loc;27185 return result_loc;
27177 }27186 }
2717827187
27179 if (result_loc->value->type->id == ZigTypeIdPointer &&27188 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);
27180 result_loc->value->type->data.pointer.is_const &&27189 if (result_loc->value->type->data.pointer.is_const) {
27181 instruction->result_loc->id == ResultLocIdInstruction &&
27182 !instruction->result_loc->allow_write_through_const)
27183 {
27184 ir_add_error(ira, &instruction->base.base, buf_sprintf("cannot assign to constant"));27190 ir_add_error(ira, &instruction->base.base, buf_sprintf("cannot assign to constant"));
27185 return ira->codegen->invalid_inst_gen;27191 return ira->codegen->invalid_inst_gen;
27186 }27192 }
...@@ -29918,15 +29924,8 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx...@@ -29918,15 +29924,8 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx
29918 return result_loc;29924 return result_loc;
2991929925
29920 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {29926 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {
29921 bool can_write_to_const_ptr = true;
29922 if (result_loc->value->type->id == ZigTypeIdPointer &&
29923 result_loc->value->type->data.pointer.is_const &&
29924 instruction->result_loc->id == ResultLocIdInstruction)
29925 {
29926 can_write_to_const_ptr = false;
29927 }
29928 IrInstGen *store_ptr = ir_analyze_store_ptr(ira, &instruction->base.base, result_loc, value,29927 IrInstGen *store_ptr = ir_analyze_store_ptr(ira, &instruction->base.base, result_loc, value,
29929 instruction->result_loc->allow_write_through_const && can_write_to_const_ptr);29928 instruction->result_loc->allow_write_through_const);
29930 if (type_is_invalid(store_ptr->value->type)) {29929 if (type_is_invalid(store_ptr->value->type)) {
29931 return ira->codegen->invalid_inst_gen;29930 return ira->codegen->invalid_inst_gen;
29932 }29931 }
test/compile_errors.zig+2-2
...@@ -10,7 +10,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -10,7 +10,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
10 \\ reassign(.{1, 2, 3});10 \\ reassign(.{1, 2, 3});
11 \\}11 \\}
12 , &[_][]const u8{12 , &[_][]const u8{
13 "tmp.zig:2:16: error: cannot assign to constant"13 "tmp.zig:2:15: error: cannot assign to constant"
14 });14 });
1515
16 cases.addTest("reassign to slice parameter",16 cases.addTest("reassign to slice parameter",
...@@ -35,7 +35,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -35,7 +35,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
35 \\ reassign(S{.x = 3});35 \\ reassign(S{.x = 3});
36 \\}36 \\}
37 , &[_][]const u8{37 , &[_][]const u8{
38 "tmp.zig:5:16: error: cannot assign to constant"38 "tmp.zig:5:10: error: cannot assign to constant"
39 });39 });
4040
41 cases.addTest("reference to const data",41 cases.addTest("reference to const data",