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
This commit is contained in:
LemonBoy 2020-12-28 11:17:14 +01:00 committed by Veikka Tuominen
parent 8aab1e2e8a
commit fffb0904f8
2 changed files with 11 additions and 1 deletions

View File

@ -13763,7 +13763,7 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstGen *type_value) {
Error err;
if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->base.source_node,
type_value->value, LazyOk)))
type_value->value, LazyOkNoUndef)))
{
return nullptr;
}

View File

@ -2,6 +2,16 @@ const tests = @import("tests.zig");
const std = @import("std");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("lazy pointer with undefined element type",
\\export fn foo() void {
\\ comptime var T: type = undefined;
\\ const S = struct { x: *T };
\\ const I = @typeInfo(S);
\\}
, &[_][]const u8{
"tmp.zig:3:28: error: use of undefined value here causes undefined behavior",
});
cases.add("pointer arithmetic on pointer-to-array",
\\export fn foo() void {
\\ var x: [10]u8 = undefined;