| author | |
| committer | |
| log | f127dee47424f4c87a4ed5026a2d5be5cce7a135 |
| tree | 46ccfd32c7990bb0772fb05f9aa804ec1e6932a8 |
| parent | 75b699b2c624d62a4b6717f00bd0856b86c3f990 |
| parent | 85fd484f0778b5f158dc76bf51b820314b86292d |
| signature | Signed by PGP key 4AEE18F83AFDEB23 |
Fix missing compile error on call assigned to const3 files changed, 35 insertions(+), 1 deletions(-)
lib/std/crypto/blake3.zig+2-1| ... | @@ -338,7 +338,7 @@ pub const Blake3 = struct { | ... | @@ -338,7 +338,7 @@ pub const Blake3 = struct { |
| 338 | } | 338 | } |
| 339 | 339 | ||
| 340 | // Section 5.1.2 of the BLAKE3 spec explains this algorithm in more detail. | 340 | // Section 5.1.2 of the BLAKE3 spec explains this algorithm in more detail. |
| 341 | fn add_chunk_chaining_value(self: *Blake3, new_cv: [8]u32, total_chunks: u64) void { | 341 | fn add_chunk_chaining_value(self: *Blake3, first_cv: [8]u32, total_chunks: u64) void { |
| 342 | // This chunk might complete some subtrees. For each completed subtree, | 342 | // This chunk might complete some subtrees. For each completed subtree, |
| 343 | // its left child will be the current top entry in the CV stack, and | 343 | // its left child will be the current top entry in the CV stack, and |
| 344 | // its right child will be the current value of `new_cv`. Pop each left | 344 | // its right child will be the current value of `new_cv`. Pop each left |
| ... | @@ -346,6 +346,7 @@ pub const Blake3 = struct { | ... | @@ -346,6 +346,7 @@ pub const Blake3 = struct { |
| 346 | // with the result. After all these merges, push the final value of | 346 | // with the result. After all these merges, push the final value of |
| 347 | // `new_cv` onto the stack. The number of completed subtrees is given | 347 | // `new_cv` onto the stack. The number of completed subtrees is given |
| 348 | // by the number of trailing 0-bits in the new total number of chunks. | 348 | // by the number of trailing 0-bits in the new total number of chunks. |
| 349 | var new_cv = first_cv; | ||
| 349 | var chunk_counter = total_chunks; | 350 | var chunk_counter = total_chunks; |
| 350 | while (chunk_counter & 1 == 0) { | 351 | while (chunk_counter & 1 == 0) { |
| 351 | new_cv = parent_cv(self.pop_cv(), new_cv, self.key, self.flags); | 352 | new_cv = parent_cv(self.pop_cv(), new_cv, self.key, self.flags); |
src/ir.cpp+10| ... | @@ -19999,6 +19999,11 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19999,6 +19999,11 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19999 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { | 19999 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 20000 | return result_loc; | 20000 | return result_loc; |
| 20001 | } | 20001 | } |
| 20002 | if (result_loc->value->type->data.pointer.is_const) { | ||
| 20003 | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); | ||
| 20004 | return ira->codegen->invalid_inst_gen; | ||
| 20005 | } | ||
| 20006 | |||
| 20002 | IrInstGen *dummy_value = ir_const(ira, source_instr, impl_fn_type_id->return_type); | 20007 | IrInstGen *dummy_value = ir_const(ira, source_instr, impl_fn_type_id->return_type); |
| 20003 | dummy_value->value->special = ConstValSpecialRuntime; | 20008 | dummy_value->value->special = ConstValSpecialRuntime; |
| 20004 | IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr, | 20009 | IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr, |
| ... | @@ -20137,6 +20142,11 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -20137,6 +20142,11 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 20137 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { | 20142 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 20138 | return result_loc; | 20143 | return result_loc; |
| 20139 | } | 20144 | } |
| 20145 | if (result_loc->value->type->data.pointer.is_const) { | ||
| 20146 | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); | ||
| 20147 | return ira->codegen->invalid_inst_gen; | ||
| 20148 | } | ||
| 20149 | |||
| 20140 | IrInstGen *dummy_value = ir_const(ira, source_instr, return_type); | 20150 | IrInstGen *dummy_value = ir_const(ira, source_instr, return_type); |
| 20141 | dummy_value->value->special = ConstValSpecialRuntime; | 20151 | dummy_value->value->special = ConstValSpecialRuntime; |
| 20142 | IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr, | 20152 | IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr, |
test/compile_errors.zig+23| ... | @@ -2,6 +2,29 @@ const tests = @import("tests.zig"); | ... | @@ -2,6 +2,29 @@ const tests = @import("tests.zig"); |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | 3 | ||
| 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add("call assigned to constant", | ||
| 6 | \\const Foo = struct { | ||
| 7 | \\ x: i32, | ||
| 8 | \\}; | ||
| 9 | \\fn foo() Foo { | ||
| 10 | \\ return .{ .x = 42 }; | ||
| 11 | \\} | ||
| 12 | \\fn bar(val: var) Foo { | ||
| 13 | \\ return .{ .x = val }; | ||
| 14 | \\} | ||
| 15 | \\export fn entry() void { | ||
| 16 | \\ const baz: Foo = undefined; | ||
| 17 | \\ baz = foo(); | ||
| 18 | \\} | ||
| 19 | \\export fn entry1() void { | ||
| 20 | \\ const baz: Foo = undefined; | ||
| 21 | \\ baz = bar(42); | ||
| 22 | \\} | ||
| 23 | , &[_][]const u8{ | ||
| 24 | "tmp.zig:12:14: error: cannot assign to constant", | ||
| 25 | "tmp.zig:16:14: error: cannot assign to constant", | ||
| 26 | }); | ||
| 27 | |||
| 5 | cases.add("invalid pointer syntax", | 28 | cases.add("invalid pointer syntax", |
| 6 | \\export fn foo() void { | 29 | \\export fn foo() void { |
| 7 | \\ var guid: *:0 const u8 = undefined; | 30 | \\ var guid: *:0 const u8 = undefined; |