| author | |
| committer | |
| log | 56b52dd0a357f87627fe96dc99377a397f3bb9a1 |
| tree | e5f493a75bf845d7c88c5ebc6fe5025afe366d15 |
| parent | 8794ce6f79886e5ebbf0476d56917e219b52c561 |
Fixes #57102 files changed, 19 insertions(+), 1 deletions(-)
src/ir.cpp+10| ... | @@ -21934,7 +21934,17 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP | ... | @@ -21934,7 +21934,17 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 21934 | return ira->codegen->invalid_inst_gen; | 21934 | return ira->codegen->invalid_inst_gen; |
| 21935 | } | 21935 | } |
| 21936 | safety_check_on = false; | 21936 | safety_check_on = false; |
| 21937 | } else if (array_type->id == ZigTypeIdVector) { | ||
| 21938 | uint64_t vector_len = array_type->data.vector.len; | ||
| 21939 | if (index >= vector_len) { | ||
| 21940 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, | ||
| 21941 | buf_sprintf("index %" ZIG_PRI_u64 " outside vector of size %" ZIG_PRI_u64, | ||
| 21942 | index, vector_len)); | ||
| 21943 | return ira->codegen->invalid_inst_gen; | ||
| 21944 | } | ||
| 21945 | safety_check_on = false; | ||
| 21937 | } | 21946 | } |
| 21947 | |||
| 21938 | if (array_type->id == ZigTypeIdVector) { | 21948 | if (array_type->id == ZigTypeIdVector) { |
| 21939 | ZigType *elem_type = array_type->data.vector.elem_type; | 21949 | ZigType *elem_type = array_type->data.vector.elem_type; |
| 21940 | uint32_t host_vec_len = array_type->data.vector.len; | 21950 | uint32_t host_vec_len = array_type->data.vector.len; |
test/compile_errors.zig+9-1| ... | @@ -2,6 +2,14 @@ const tests = @import("tests.zig"); | ... | @@ -2,6 +2,14 @@ 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("slice sentinel mismatch", | ||
| 6 | \\export fn entry() void { | ||
| 7 | \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 }; | ||
| 8 | \\} | ||
| 9 | , &[_][]const u8{ | ||
| 10 | "tmp.zig:2:62: error: index 3 outside vector of size 3", | ||
| 11 | }); | ||
| 12 | |||
| 5 | cases.add("slice sentinel mismatch", | 13 | cases.add("slice sentinel mismatch", |
| 6 | \\export fn entry() void { | 14 | \\export fn entry() void { |
| 7 | \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; | 15 | \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; |
| ... | @@ -7548,7 +7556,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7548,7 +7556,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7548 | }); | 7556 | }); |
| 7549 | 7557 | ||
| 7550 | cases.add( // fixed bug #2032 | 7558 | cases.add( // fixed bug #2032 |
| 7551 | "compile diagnostic string for top level decl type", | 7559 | "compile diagnostic string for top level decl type", |
| 7552 | \\export fn entry() void { | 7560 | \\export fn entry() void { |
| 7553 | \\ var foo: u32 = @This(){}; | 7561 | \\ var foo: u32 = @This(){}; |
| 7554 | \\} | 7562 | \\} |