authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-10-16 09:16:12+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-10-16 17:13:38+03:00
log2a62d4b20be9b99f53367e74434e1971ced78848
treedcff5a330112ddd1fe5f7adc806923f8fe65ccde
parent996a2284dde16b030a63cb9ba42f586c7a1b66cd

stage1: Expand undefined struct/arrays when indexed

Fixes #6693

2 files changed, 14 insertions(+), 1 deletions(-)

src/stage1/ir.cpp+4
......@@ -22188,6 +22188,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
2218822188 }
2218922189 return result;
2219022190 } else if (is_slice(array_type)) {
22191 expand_undef_struct(ira->codegen, array_ptr_val);
22192
2219122193 ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];
2219222194 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base.base);
2219322195 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
......@@ -22252,6 +22254,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
2225222254 }
2225322255 return result;
2225422256 } else if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) {
22257 expand_undef_array(ira->codegen, array_ptr_val);
22258
2225522259 IrInstGen *result;
2225622260 if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
2225722261 result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
test/compile_errors.zig+10-1
......@@ -2,6 +2,15 @@ const tests = @import("tests.zig");
22const std = @import("std");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add("indexing a undefined slice at comptime",
6 \\comptime {
7 \\ var slice: []u8 = undefined;
8 \\ slice[0] = 2;
9 \\}
10 , &[_][]const u8{
11 "tmp.zig:3:10: error: index 0 outside slice of size 0",
12 });
13
514 cases.add("array in c exported function",
615 \\export fn zig_array(x: [10]u8) void {
716 \\ expect(std.mem.eql(u8, &x, "1234567890"));
......@@ -7714,7 +7723,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
77147723 });
77157724
77167725 cases.add( // fixed bug #2032
7717 "compile diagnostic string for top level decl type",
7726 "compile diagnostic string for top level decl type",
77187727 \\export fn entry() void {
77197728 \\ var foo: u32 = @This(){};
77207729 \\}