authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-05 10:43:35-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-05 10:43:35-04:00
loga76a72469bf5980946fad8f8e60f07edde543ce5
tree8a4f5bba088b64e26d13c0e509bfd66ba3d64224
parent3e94650ef7bd2407fb0aca11ad19a93b90a14b7c
signaturelock-open Commit is signed but in an unrecognized format.

stage1: fix crash when invalid type used in array type

closes #1186

2 files changed, 17 insertions(+), 0 deletions(-)

src/ir.cpp+4
...@@ -15474,6 +15474,8 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA...@@ -15474,6 +15474,8 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA
15474static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,15474static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
15475 IrInstructionArrayType *array_type_instruction)15475 IrInstructionArrayType *array_type_instruction)
15476{15476{
15477 Error err;
15478
15477 IrInstruction *size_value = array_type_instruction->size->other;15479 IrInstruction *size_value = array_type_instruction->size->other;
15478 uint64_t size;15480 uint64_t size;
15479 if (!ir_resolve_usize(ira, size_value, &size))15481 if (!ir_resolve_usize(ira, size_value, &size))
...@@ -15515,6 +15517,8 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -15515,6 +15517,8 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
15515 case TypeTableEntryIdBoundFn:15517 case TypeTableEntryIdBoundFn:
15516 case TypeTableEntryIdPromise:15518 case TypeTableEntryIdPromise:
15517 {15519 {
15520 if ((err = ensure_complete_type(ira->codegen, child_type)))
15521 return ira->codegen->builtin_types.entry_invalid;
15518 TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size);15522 TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size);
15519 ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base);15523 ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base);
15520 out_val->data.x_type = result_type;15524 out_val->data.x_type = result_type;
test/compile_errors.zig+13
...@@ -1,6 +1,19 @@...@@ -1,6 +1,19 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "invalid type used in array type",
6 \\const Item = struct {
7 \\ field: SomeNonexistentType,
8 \\};
9 \\var items: [100]Item = undefined;
10 \\export fn entry() void {
11 \\ const a = items[0];
12 \\}
13 ,
14 ".tmp_source.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'",
15 );
16
4 cases.add(17 cases.add(
5 "@noInlineCall on an inline function",18 "@noInlineCall on an inline function",
6 \\inline fn foo() void {}19 \\inline fn foo() void {}