aboutsummaryrefslogtreecommitdiff
path: root/src/stage1/ir.cpp
diff options
context:
space:
mode:
authorMichael Dusan <michael.dusan@gmail.com>2021-01-18 00:36:37 -0500
committerVeikka Tuominen <git@vexu.eu>2021-01-30 11:19:25 +0200
commitf9b85c6e50e22153aff4c87e2ba943d68f24ee8c (patch)
tree0a5825a3c0f930f80f08f596c6f1750d57366252 /src/stage1/ir.cpp
parent3d4eeafb47f97e5057d36fe2c3ed061cf0c70a63 (diff)
downloadzig-f9b85c6e50e22153aff4c87e2ba943d68f24ee8c.tar.gz
zig-f9b85c6e50e22153aff4c87e2ba943d68f24ee8c.zip
stage1: add error for slice.len incr beyond bounds
comptime direct slice.len increment dodges bounds checking but we can emit an error for it, at least in the simple case. - promote original assert to compile-error - add test case closes #7810
Diffstat (limited to 'src/stage1/ir.cpp')
-rw-r--r--src/stage1/ir.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp
index e39e44c3fd..9fd6f15873 100644
--- a/src/stage1/ir.cpp
+++ b/src/stage1/ir.cpp
@@ -22655,9 +22655,10 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
if (ptr_field->data.x_ptr.data.base_array.array_val->data.x_array.special !=
ConstArraySpecialBuf)
{
- ir_assert(new_index <
- ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len,
- &elem_ptr_instruction->base.base);
+ if (new_index >= ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len) {
+ ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf("out of bounds slice"));
+ return ira->codegen->invalid_inst_gen;
+ }
}
out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
out_val->data.x_ptr.data.base_array.array_val =