authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-12-28 11:17:14+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-12-28 15:27:31+02:00
logfffb0904f898d47800aa418085dc6064d02c32fe
treec29e9ba6d134117372b6dd088637ff947068cef5
parent8aab1e2e8ad1451a22a48109006babf463a09e9e

stage1: Prevent crash with some lazy pointer types

Make sure the child element is not undefined, let's catch this problem early on. Closes #7568

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

src/stage1/ir.cpp+1-1
...@@ -13763,7 +13763,7 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstGen *type_value) {...@@ -13763,7 +13763,7 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstGen *type_value) {
1376313763
13764 Error err;13764 Error err;
13765 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->base.source_node,13765 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->base.source_node,
13766 type_value->value, LazyOk)))13766 type_value->value, LazyOkNoUndef)))
13767 {13767 {
13768 return nullptr;13768 return nullptr;
13769 }13769 }
test/compile_errors.zig+10
...@@ -2,6 +2,16 @@ const tests = @import("tests.zig");...@@ -2,6 +2,16 @@ const tests = @import("tests.zig");
2const std = @import("std");2const std = @import("std");
33
4pub fn addCases(cases: *tests.CompileErrorContext) void {4pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add("lazy pointer with undefined element type",
6 \\export fn foo() void {
7 \\ comptime var T: type = undefined;
8 \\ const S = struct { x: *T };
9 \\ const I = @typeInfo(S);
10 \\}
11 , &[_][]const u8{
12 "tmp.zig:3:28: error: use of undefined value here causes undefined behavior",
13 });
14
5 cases.add("pointer arithmetic on pointer-to-array",15 cases.add("pointer arithmetic on pointer-to-array",
6 \\export fn foo() void {16 \\export fn foo() void {
7 \\ var x: [10]u8 = undefined;17 \\ var x: [10]u8 = undefined;