aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorxackus <14938807+xackus@users.noreply.github.com>2020-04-23 03:06:41 +0200
committerAndrew Kelley <andrew@ziglang.org>2020-04-23 12:45:32 -0400
commita9eb4a6740e0bb00e1984de3768a7de6001c25dd (patch)
tree5677ec8acfae34ec61eb74d775dc4289193c3224 /src/ir.cpp
parente6428f94013132b6a6284b053afb36d35af63c59 (diff)
downloadzig-a9eb4a6740e0bb00e1984de3768a7de6001c25dd.tar.gz
zig-a9eb4a6740e0bb00e1984de3768a7de6001c25dd.zip
stage1: fix crash on accessing an array of size zero with runtime index
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 00bd83f95e..5c8d8157d2 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -21199,6 +21199,11 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
}
if (array_type->id == ZigTypeIdArray) {
+ if(array_type->data.array.len == 0 && array_type->data.array.sentinel == nullptr){
+ ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf("accessing a zero length array is not allowed"));
+ return ira->codegen->invalid_inst_gen;
+ }
+
ZigType *child_type = array_type->data.array.child_type;
if (ptr_type->data.pointer.host_int_bytes == 0) {
return_type = get_pointer_to_type_extra(ira->codegen, child_type,