authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-25 18:06:03-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-25 18:06:03-04:00
log0a773259167158f47198ddd3564405604eb03014
tree7806e929e161bfab7b245ab64c3982c8909013de
parentda68aec3393648fd89262b2142766d9f734720dc
signaturelock-open Commit is signed but in an unrecognized format.

fix several compile error test regressions


2 files changed, 52 insertions(+), 34 deletions(-)

src/ir.cpp+8-14
......@@ -5579,7 +5579,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
55795579 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "Else");
55805580 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "EndIf");
55815581
5582 IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, condition->source_node, condition,
5582 IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, condition,
55835583 then_block, else_block, is_comptime);
55845584 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
55855585 result_loc, is_comptime);
......@@ -5833,7 +5833,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
58335833 Buf *name = entry_node->data.struct_val_field.name;
58345834 AstNode *expr_node = entry_node->data.struct_val_field.expr;
58355835
5836 IrInstruction *field_ptr = ir_build_field_ptr(irb, scope, expr_node, container_ptr, name, true);
5836 IrInstruction *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true);
58375837 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
58385838 result_loc_inst->base.id = ResultLocIdInstruction;
58395839 result_loc_inst->base.source_instruction = field_ptr;
......@@ -16822,11 +16822,6 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1682216822 peer_parent->done_resuming = true;
1682316823 return ira_resume(ira);
1682416824 }
16825 if (peer_parent != nullptr && !peer_parent->skipped && peer_parent->base.resolved_loc != nullptr &&
16826 type_is_invalid(peer_parent->base.resolved_loc->value.type))
16827 {
16828 return ira->codegen->invalid_instruction;
16829 }
1683016825
1683116826 ZigList<IrBasicBlock*> new_incoming_blocks = {0};
1683216827 ZigList<IrInstruction*> new_incoming_values = {0};
......@@ -17688,7 +17683,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
1768817683 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type, field_ptr_instruction->initializing);
1768917684 return result;
1769017685 }
17691 } else if (is_array_ref(container_type)) {
17686 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
1769217687 if (buf_eql_str(field_name, "len")) {
1769317688 ConstExprValue *len_val = create_const_vals(1);
1769417689 if (container_type->id == ZigTypeIdPointer) {
......@@ -18003,6 +17998,10 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
1800317998 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));
1800417999 return ira->codegen->invalid_instruction;
1800518000 }
18001 } else if (field_ptr_instruction->initializing) {
18002 ir_add_error(ira, &field_ptr_instruction->base,
18003 buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name)));
18004 return ira->codegen->invalid_instruction;
1800618005 } else {
1800718006 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
1800818007 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));
......@@ -24796,11 +24795,6 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
2479624795 if (!was_written) {
2479724796 IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value);
2479824797 if (type_is_invalid(store_ptr->value.type)) {
24799 instruction->result_loc->resolved_loc = ira->codegen->invalid_instruction;
24800 if (instruction->result_loc->id == ResultLocIdPeer) {
24801 reinterpret_cast<ResultLocPeer *>(instruction->result_loc)->parent->base.resolved_loc =
24802 ira->codegen->invalid_instruction;
24803 }
2480424798 return ira->codegen->invalid_instruction;
2480524799 }
2480624800 }
......@@ -25198,7 +25192,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2519825192 ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction);
2519925193 old_instruction->child = new_instruction;
2520025194
25201 if (type_is_invalid(new_instruction->value.type) && ir_should_inline(new_exec, old_instruction->scope)) {
25195 if (type_is_invalid(new_instruction->value.type)) {
2520225196 return ira->codegen->builtin_types.entry_invalid;
2520325197 }
2520425198
test/compile_errors.zig+44-20
......@@ -49,16 +49,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4949 \\const Foo = struct {
5050 \\ a: undefined,
5151 \\};
52 \\const Bar = union {
53 \\ a: undefined,
54 \\};
55 \\pub fn main() void {
52 \\export fn entry1() void {
5653 \\ const foo: Foo = undefined;
57 \\ const bar: Bar = undefined;
5854 \\}
5955 ,
6056 "tmp.zig:2:8: error: expected type 'type', found '(undefined)'",
61 "tmp.zig:5:8: error: expected type 'type', found '(undefined)'",
6257 );
6358
6459 cases.add(
......@@ -461,13 +456,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
461456 \\const G = packed struct {
462457 \\ x: Enum,
463458 \\};
464 \\export fn entry() void {
459 \\export fn entry1() void {
465460 \\ var a: A = undefined;
461 \\}
462 \\export fn entry2() void {
466463 \\ var b: B = undefined;
464 \\}
465 \\export fn entry3() void {
467466 \\ var r: C = undefined;
467 \\}
468 \\export fn entry4() void {
468469 \\ var d: D = undefined;
470 \\}
471 \\export fn entry5() void {
469472 \\ var e: E = undefined;
473 \\}
474 \\export fn entry6() void {
470475 \\ var f: F = undefined;
476 \\}
477 \\export fn entry7() void {
471478 \\ var g: G = undefined;
472479 \\}
473480 \\const S = struct {
......@@ -489,7 +496,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
489496 "tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation",
490497 "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation",
491498 "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation",
492 "tmp.zig:38:14: note: enum declaration does not specify an integer tag type",
499 "tmp.zig:50:14: note: enum declaration does not specify an integer tag type",
493500 );
494501
495502 cases.addCase(x: {
......@@ -721,7 +728,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
721728 \\ var oops = @bitCast(u7, byte);
722729 \\}
723730 ,
724 "tmp.zig:2:16: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits",
731 "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits",
725732 );
726733
727734 cases.add(
......@@ -1381,7 +1388,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
13811388 \\ for (xx) |f| {}
13821389 \\}
13831390 ,
1384 "tmp.zig:7:15: error: variable of type 'Foo' must be const or comptime",
1391 "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known",
13851392 );
13861393
13871394 cases.add(
......@@ -2250,6 +2257,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
22502257 \\}
22512258 \\
22522259 \\extern fn bar(x: *void) void { }
2260 \\export fn entry2() void {
2261 \\ bar(&{});
2262 \\}
22532263 ,
22542264 "tmp.zig:1:30: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",
22552265 "tmp.zig:7:18: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",
......@@ -2576,7 +2586,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
25762586 \\
25772587 \\fn b() void {}
25782588 ,
2579 "tmp.zig:3:5: error: unreachable code",
2589 "tmp.zig:3:6: error: unreachable code",
25802590 );
25812591
25822592 cases.add(
......@@ -2596,7 +2606,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
25962606 \\}
25972607 ,
25982608 "tmp.zig:3:5: error: use of undeclared identifier 'b'",
2599 "tmp.zig:4:5: error: use of undeclared identifier 'c'",
26002609 );
26012610
26022611 cases.add(
......@@ -2662,7 +2671,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
26622671 \\ const a: noreturn = {};
26632672 \\}
26642673 ,
2665 "tmp.zig:2:14: error: variable of type 'noreturn' not allowed",
2674 "tmp.zig:2:25: error: expected type 'noreturn', found 'void'",
26662675 );
26672676
26682677 cases.add(
......@@ -2725,9 +2734,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
27252734 \\ var bad : bool = undefined;
27262735 \\ bad[bad] = bad[bad];
27272736 \\}
2737 \\export fn g() void {
2738 \\ var bad : bool = undefined;
2739 \\ _ = bad[bad];
2740 \\}
27282741 ,
27292742 "tmp.zig:3:8: error: array access of non-array type 'bool'",
2730 "tmp.zig:3:19: error: array access of non-array type 'bool'",
2743 "tmp.zig:7:12: error: array access of non-array type 'bool'",
27312744 );
27322745
27332746 cases.add(
......@@ -2737,9 +2750,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
27372750 \\ var bad = false;
27382751 \\ array[bad] = array[bad];
27392752 \\}
2753 \\export fn g() void {
2754 \\ var array = "aoeu";
2755 \\ var bad = false;
2756 \\ _ = array[bad];
2757 \\}
27402758 ,
27412759 "tmp.zig:4:11: error: expected type 'usize', found 'bool'",
2742 "tmp.zig:4:24: error: expected type 'usize', found 'bool'",
2760 "tmp.zig:9:15: error: expected type 'usize', found 'bool'",
27432761 );
27442762
27452763 cases.add(
......@@ -2757,12 +2775,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
27572775 "missing else clause",
27582776 \\fn f(b: bool) void {
27592777 \\ const x : i32 = if (b) h: { break :h 1; };
2778 \\}
2779 \\fn g(b: bool) void {
27602780 \\ const y = if (b) h: { break :h i32(1); };
27612781 \\}
2762 \\export fn entry() void { f(true); }
2782 \\export fn entry() void { f(true); g(true); }
27632783 ,
27642784 "tmp.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'",
2765 "tmp.zig:3:15: error: incompatible types: 'i32' and 'void'",
2785 "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'",
27662786 );
27672787
27682788 cases.add(
......@@ -2773,9 +2793,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
27732793 \\ a.foo = 1;
27742794 \\ const y = a.bar;
27752795 \\}
2796 \\export fn g() void {
2797 \\ var a : A = undefined;
2798 \\ const y = a.bar;
2799 \\}
27762800 ,
27772801 "tmp.zig:4:6: error: no member named 'foo' in struct 'A'",
2778 "tmp.zig:5:16: error: no member named 'bar' in struct 'A'",
2802 "tmp.zig:9:16: error: no member named 'bar' in struct 'A'",
27792803 );
27802804
27812805 cases.add(
......@@ -2920,7 +2944,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29202944 \\ _ = foo;
29212945 \\}
29222946 ,
2923 "tmp.zig:1:19: error: type '[3]u16' does not support struct initialization syntax",
2947 "tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax",
29242948 );
29252949
29262950 cases.add(
......@@ -3239,7 +3263,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
32393263 \\
32403264 \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); }
32413265 ,
3242 "tmp.zig:5:25: error: unable to evaluate constant expression",
3266 "tmp.zig:5:18: error: unable to evaluate constant expression",
32433267 "tmp.zig:2:12: note: called from here",
32443268 "tmp.zig:2:8: note: called from here",
32453269 );