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...@@ -5579,7 +5579,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
5579 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "Else");5579 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "Else");
5580 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "EndIf");5580 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,
5583 then_block, else_block, is_comptime);5583 then_block, else_block, is_comptime);
5584 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,5584 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
5585 result_loc, is_comptime);5585 result_loc, is_comptime);
...@@ -5833,7 +5833,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -5833,7 +5833,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
5833 Buf *name = entry_node->data.struct_val_field.name;5833 Buf *name = entry_node->data.struct_val_field.name;
5834 AstNode *expr_node = entry_node->data.struct_val_field.expr;5834 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);
5837 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);5837 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
5838 result_loc_inst->base.id = ResultLocIdInstruction;5838 result_loc_inst->base.id = ResultLocIdInstruction;
5839 result_loc_inst->base.source_instruction = field_ptr;5839 result_loc_inst->base.source_instruction = field_ptr;
...@@ -16822,11 +16822,6 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -16822,11 +16822,6 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
16822 peer_parent->done_resuming = true;16822 peer_parent->done_resuming = true;
16823 return ira_resume(ira);16823 return ira_resume(ira);
16824 }16824 }
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
16831 ZigList<IrBasicBlock*> new_incoming_blocks = {0};16826 ZigList<IrBasicBlock*> new_incoming_blocks = {0};
16832 ZigList<IrInstruction*> new_incoming_values = {0};16827 ZigList<IrInstruction*> new_incoming_values = {0};
...@@ -17688,7 +17683,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -17688,7 +17683,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
17688 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type, field_ptr_instruction->initializing);17683 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type, field_ptr_instruction->initializing);
17689 return result;17684 return result;
17690 }17685 }
17691 } else if (is_array_ref(container_type)) {17686 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
17692 if (buf_eql_str(field_name, "len")) {17687 if (buf_eql_str(field_name, "len")) {
17693 ConstExprValue *len_val = create_const_vals(1);17688 ConstExprValue *len_val = create_const_vals(1);
17694 if (container_type->id == ZigTypeIdPointer) {17689 if (container_type->id == ZigTypeIdPointer) {
...@@ -18003,6 +17998,10 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -18003,6 +17998,10 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
18003 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));17998 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));
18004 return ira->codegen->invalid_instruction;17999 return ira->codegen->invalid_instruction;
18005 }18000 }
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;
18006 } else {18005 } else {
18007 ir_add_error_node(ira, field_ptr_instruction->base.source_node,18006 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
18008 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));18007 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...@@ -24796,11 +24795,6 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
24796 if (!was_written) {24795 if (!was_written) {
24797 IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value);24796 IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value);
24798 if (type_is_invalid(store_ptr->value.type)) {24797 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 }
24804 return ira->codegen->invalid_instruction;24798 return ira->codegen->invalid_instruction;
24805 }24799 }
24806 }24800 }
...@@ -25198,7 +25192,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -25198,7 +25192,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
25198 ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction);25192 ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction);
25199 old_instruction->child = new_instruction;25193 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)) {
25202 return ira->codegen->builtin_types.entry_invalid;25196 return ira->codegen->builtin_types.entry_invalid;
25203 }25197 }
2520425198
test/compile_errors.zig+44-20
...@@ -49,16 +49,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -49,16 +49,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
49 \\const Foo = struct {49 \\const Foo = struct {
50 \\ a: undefined,50 \\ a: undefined,
51 \\};51 \\};
52 \\const Bar = union {52 \\export fn entry1() void {
53 \\ a: undefined,
54 \\};
55 \\pub fn main() void {
56 \\ const foo: Foo = undefined;53 \\ const foo: Foo = undefined;
57 \\ const bar: Bar = undefined;
58 \\}54 \\}
59 ,55 ,
60 "tmp.zig:2:8: error: expected type 'type', found '(undefined)'",56 "tmp.zig:2:8: error: expected type 'type', found '(undefined)'",
61 "tmp.zig:5:8: error: expected type 'type', found '(undefined)'",
62 );57 );
6358
64 cases.add(59 cases.add(
...@@ -461,13 +456,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -461,13 +456,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
461 \\const G = packed struct {456 \\const G = packed struct {
462 \\ x: Enum,457 \\ x: Enum,
463 \\};458 \\};
464 \\export fn entry() void {459 \\export fn entry1() void {
465 \\ var a: A = undefined;460 \\ var a: A = undefined;
461 \\}
462 \\export fn entry2() void {
466 \\ var b: B = undefined;463 \\ var b: B = undefined;
464 \\}
465 \\export fn entry3() void {
467 \\ var r: C = undefined;466 \\ var r: C = undefined;
467 \\}
468 \\export fn entry4() void {
468 \\ var d: D = undefined;469 \\ var d: D = undefined;
470 \\}
471 \\export fn entry5() void {
469 \\ var e: E = undefined;472 \\ var e: E = undefined;
473 \\}
474 \\export fn entry6() void {
470 \\ var f: F = undefined;475 \\ var f: F = undefined;
476 \\}
477 \\export fn entry7() void {
471 \\ var g: G = undefined;478 \\ var g: G = undefined;
472 \\}479 \\}
473 \\const S = struct {480 \\const S = struct {
...@@ -489,7 +496,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -489,7 +496,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
489 "tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation",496 "tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation",
490 "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation",497 "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation",
491 "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation",498 "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",
493 );500 );
494501
495 cases.addCase(x: {502 cases.addCase(x: {
...@@ -721,7 +728,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -721,7 +728,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
721 \\ var oops = @bitCast(u7, byte);728 \\ var oops = @bitCast(u7, byte);
722 \\}729 \\}
723 ,730 ,
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",
725 );732 );
726733
727 cases.add(734 cases.add(
...@@ -1381,7 +1388,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1381,7 +1388,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1381 \\ for (xx) |f| {}1388 \\ for (xx) |f| {}
1382 \\}1389 \\}
1383 ,1390 ,
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",
1385 );1392 );
13861393
1387 cases.add(1394 cases.add(
...@@ -2250,6 +2257,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2250,6 +2257,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2250 \\}2257 \\}
2251 \\2258 \\
2252 \\extern fn bar(x: *void) void { }2259 \\extern fn bar(x: *void) void { }
2260 \\export fn entry2() void {
2261 \\ bar(&{});
2262 \\}
2253 ,2263 ,
2254 "tmp.zig:1:30: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",2264 "tmp.zig:1:30: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",
2255 "tmp.zig:7:18: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",2265 "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 {...@@ -2576,7 +2586,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2576 \\2586 \\
2577 \\fn b() void {}2587 \\fn b() void {}
2578 ,2588 ,
2579 "tmp.zig:3:5: error: unreachable code",2589 "tmp.zig:3:6: error: unreachable code",
2580 );2590 );
25812591
2582 cases.add(2592 cases.add(
...@@ -2596,7 +2606,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2596,7 +2606,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2596 \\}2606 \\}
2597 ,2607 ,
2598 "tmp.zig:3:5: error: use of undeclared identifier 'b'",2608 "tmp.zig:3:5: error: use of undeclared identifier 'b'",
2599 "tmp.zig:4:5: error: use of undeclared identifier 'c'",
2600 );2609 );
26012610
2602 cases.add(2611 cases.add(
...@@ -2662,7 +2671,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2662,7 +2671,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2662 \\ const a: noreturn = {};2671 \\ const a: noreturn = {};
2663 \\}2672 \\}
2664 ,2673 ,
2665 "tmp.zig:2:14: error: variable of type 'noreturn' not allowed",2674 "tmp.zig:2:25: error: expected type 'noreturn', found 'void'",
2666 );2675 );
26672676
2668 cases.add(2677 cases.add(
...@@ -2725,9 +2734,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2725,9 +2734,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2725 \\ var bad : bool = undefined;2734 \\ var bad : bool = undefined;
2726 \\ bad[bad] = bad[bad];2735 \\ bad[bad] = bad[bad];
2727 \\}2736 \\}
2737 \\export fn g() void {
2738 \\ var bad : bool = undefined;
2739 \\ _ = bad[bad];
2740 \\}
2728 ,2741 ,
2729 "tmp.zig:3:8: error: array access of non-array type 'bool'",2742 "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'",
2731 );2744 );
27322745
2733 cases.add(2746 cases.add(
...@@ -2737,9 +2750,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2737,9 +2750,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2737 \\ var bad = false;2750 \\ var bad = false;
2738 \\ array[bad] = array[bad];2751 \\ array[bad] = array[bad];
2739 \\}2752 \\}
2753 \\export fn g() void {
2754 \\ var array = "aoeu";
2755 \\ var bad = false;
2756 \\ _ = array[bad];
2757 \\}
2740 ,2758 ,
2741 "tmp.zig:4:11: error: expected type 'usize', found 'bool'",2759 "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'",
2743 );2761 );
27442762
2745 cases.add(2763 cases.add(
...@@ -2757,12 +2775,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2757,12 +2775,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2757 "missing else clause",2775 "missing else clause",
2758 \\fn f(b: bool) void {2776 \\fn f(b: bool) void {
2759 \\ const x : i32 = if (b) h: { break :h 1; };2777 \\ const x : i32 = if (b) h: { break :h 1; };
2778 \\}
2779 \\fn g(b: bool) void {
2760 \\ const y = if (b) h: { break :h i32(1); };2780 \\ const y = if (b) h: { break :h i32(1); };
2761 \\}2781 \\}
2762 \\export fn entry() void { f(true); }2782 \\export fn entry() void { f(true); g(true); }
2763 ,2783 ,
2764 "tmp.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'",2784 "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'",
2766 );2786 );
27672787
2768 cases.add(2788 cases.add(
...@@ -2773,9 +2793,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2773,9 +2793,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2773 \\ a.foo = 1;2793 \\ a.foo = 1;
2774 \\ const y = a.bar;2794 \\ const y = a.bar;
2775 \\}2795 \\}
2796 \\export fn g() void {
2797 \\ var a : A = undefined;
2798 \\ const y = a.bar;
2799 \\}
2776 ,2800 ,
2777 "tmp.zig:4:6: error: no member named 'foo' in struct 'A'",2801 "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'",
2779 );2803 );
27802804
2781 cases.add(2805 cases.add(
...@@ -2920,7 +2944,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2920,7 +2944,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2920 \\ _ = foo;2944 \\ _ = foo;
2921 \\}2945 \\}
2922 ,2946 ,
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",
2924 );2948 );
29252949
2926 cases.add(2950 cases.add(
...@@ -3239,7 +3263,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3239,7 +3263,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3239 \\3263 \\
3240 \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); }3264 \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); }
3241 ,3265 ,
3242 "tmp.zig:5:25: error: unable to evaluate constant expression",3266 "tmp.zig:5:18: error: unable to evaluate constant expression",
3243 "tmp.zig:2:12: note: called from here",3267 "tmp.zig:2:12: note: called from here",
3244 "tmp.zig:2:8: note: called from here",3268 "tmp.zig:2:8: note: called from here",
3245 );3269 );