| author | |
| committer | |
| log | bad4b040cca553ae6845b18f268313f02077f6c1 |
| tree | ac91a35d13920be9cef9f35a4f655b956c2fb36e |
| parent | ca145a6d5a430cd87d0b242fb7453e8249221cd0 |
| signature |
5 files changed, 84 insertions(+), 50 deletions(-)
src/all_types.hpp+3| ... | ... | @@ -363,8 +363,10 @@ struct LazyValueFnType { |
| 363 | 363 | |
| 364 | 364 | AstNode *proto_node; |
| 365 | 365 | ConstExprValue **param_types; |
| 366 | AstNode **param_type_src_nodes; | |
| 366 | 367 | ConstExprValue *align_val; // can be null |
| 367 | 368 | ConstExprValue *return_type; |
| 369 | AstNode *return_type_src_node; | |
| 368 | 370 | }; |
| 369 | 371 | |
| 370 | 372 | struct ConstExprValue { |
| ... | ... | @@ -1026,6 +1028,7 @@ struct AstNodeEnumLiteral { |
| 1026 | 1028 | |
| 1027 | 1029 | struct AstNode { |
| 1028 | 1030 | enum NodeType type; |
| 1031 | bool already_traced_this_node; | |
| 1029 | 1032 | size_t line; |
| 1030 | 1033 | size_t column; |
| 1031 | 1034 | ZigType *owner; |
src/analyze.cpp+8-6| ... | ... | @@ -63,10 +63,11 @@ ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg) { |
| 63 | 63 | return err; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | ErrorMsg *add_node_error(CodeGen *g, const AstNode *node, Buf *msg) { | |
| 66 | ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) { | |
| 67 | 67 | Token fake_token; |
| 68 | 68 | fake_token.start_line = node->line; |
| 69 | 69 | fake_token.start_column = node->column; |
| 70 | node->already_traced_this_node = true; | |
| 70 | 71 | return add_token_error(g, node->owner, &fake_token, msg); |
| 71 | 72 | } |
| 72 | 73 | |
| ... | ... | @@ -1782,7 +1783,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 1782 | 1783 | if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) { |
| 1783 | 1784 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| 1784 | 1785 | add_node_error(g, decl_node, |
| 1785 | buf_sprintf("struct '%s' depends on its own size", buf_ptr(&struct_type->name))); | |
| 1786 | buf_sprintf("struct '%s' depends on itself", buf_ptr(&struct_type->name))); | |
| 1786 | 1787 | } |
| 1787 | 1788 | return ErrorSemanticAnalyzeFail; |
| 1788 | 1789 | } |
| ... | ... | @@ -1936,7 +1937,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) { |
| 1936 | 1937 | if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) { |
| 1937 | 1938 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 1938 | 1939 | add_node_error(g, decl_node, |
| 1939 | buf_sprintf("union '%s' depends on its own alignment", buf_ptr(&union_type->name))); | |
| 1940 | buf_sprintf("union '%s' depends on itself", buf_ptr(&union_type->name))); | |
| 1940 | 1941 | } |
| 1941 | 1942 | return ErrorSemanticAnalyzeFail; |
| 1942 | 1943 | } |
| ... | ... | @@ -2047,7 +2048,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { |
| 2047 | 2048 | if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) { |
| 2048 | 2049 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 2049 | 2050 | add_node_error(g, decl_node, |
| 2050 | buf_sprintf("union '%s' depends on its own size", buf_ptr(&union_type->name))); | |
| 2051 | buf_sprintf("union '%s' depends on itself", buf_ptr(&union_type->name))); | |
| 2051 | 2052 | } |
| 2052 | 2053 | return ErrorSemanticAnalyzeFail; |
| 2053 | 2054 | } |
| ... | ... | @@ -2452,7 +2453,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) { |
| 2452 | 2453 | if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) { |
| 2453 | 2454 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| 2454 | 2455 | add_node_error(g, decl_node, |
| 2455 | buf_sprintf("struct '%s' depends on its own alignment", buf_ptr(&struct_type->name))); | |
| 2456 | buf_sprintf("struct '%s' depends on itself", buf_ptr(&struct_type->name))); | |
| 2456 | 2457 | } |
| 2457 | 2458 | return ErrorSemanticAnalyzeFail; |
| 2458 | 2459 | } |
| ... | ... | @@ -3661,8 +3662,9 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node, bool all |
| 3661 | 3662 | } |
| 3662 | 3663 | } |
| 3663 | 3664 | |
| 3664 | if (g->trace_err != nullptr && source_node != nullptr) { | |
| 3665 | if (g->trace_err != nullptr && source_node != nullptr && !source_node->already_traced_this_node) { | |
| 3665 | 3666 | g->trace_err = add_error_note(g, g->trace_err, source_node, buf_create_from_str("referenced here")); |
| 3667 | source_node->already_traced_this_node = true; | |
| 3666 | 3668 | } |
| 3667 | 3669 | } |
| 3668 | 3670 |
src/analyze.hpp+1-1| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | #include "all_types.hpp" |
| 12 | 12 | |
| 13 | 13 | void semantic_analyze(CodeGen *g); |
| 14 | ErrorMsg *add_node_error(CodeGen *g, const AstNode *node, Buf *msg); | |
| 14 | ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg); | |
| 15 | 15 | ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg); |
| 16 | 16 | ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, const AstNode *node, Buf *msg); |
| 17 | 17 | ZigType *new_type_table_entry(ZigTypeId id); |
src/ir.cpp+35-8| ... | ... | @@ -10818,6 +10818,8 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod |
| 10818 | 10818 | } |
| 10819 | 10819 | |
| 10820 | 10820 | ConstExprValue *result = ir_exec_const_result(codegen, analyzed_executable); |
| 10821 | if (type_is_invalid(result->type)) | |
| 10822 | return &codegen->invalid_instruction->value; | |
| 10821 | 10823 | |
| 10822 | 10824 | if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed))) |
| 10823 | 10825 | return &codegen->invalid_instruction->value; |
| ... | ... | @@ -14330,6 +14332,10 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 14330 | 14332 | // since it's a comptime val there are no instructions for it. |
| 14331 | 14333 | // we memcpy the init value here |
| 14332 | 14334 | IrInstruction *deref = ir_get_deref(ira, var_ptr, var_ptr, nullptr); |
| 14335 | if (type_is_invalid(deref->value.type)) { | |
| 14336 | var->var_type = ira->codegen->builtin_types.entry_invalid; | |
| 14337 | return ira->codegen->invalid_instruction; | |
| 14338 | } | |
| 14333 | 14339 | // If this assertion trips, something is wrong with the IR instructions, because |
| 14334 | 14340 | // we expected the above deref to return a constant value, but it created a runtime |
| 14335 | 14341 | // instruction. |
| ... | ... | @@ -21957,6 +21963,11 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 21957 | 21963 | if (slice_ptr == nullptr) |
| 21958 | 21964 | return ira->codegen->invalid_instruction; |
| 21959 | 21965 | |
| 21966 | if (slice_ptr->special == ConstValSpecialUndef) { | |
| 21967 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined")); | |
| 21968 | return ira->codegen->invalid_instruction; | |
| 21969 | } | |
| 21970 | ||
| 21960 | 21971 | parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index]; |
| 21961 | 21972 | if (parent_ptr->special == ConstValSpecialUndef) { |
| 21962 | 21973 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined")); |
| ... | ... | @@ -22836,6 +22847,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 22836 | 22847 | size_t param_count = proto_node->data.fn_proto.params.length; |
| 22837 | 22848 | lazy_fn_type->proto_node = proto_node; |
| 22838 | 22849 | lazy_fn_type->param_types = allocate<ConstExprValue *>(param_count); |
| 22850 | lazy_fn_type->param_type_src_nodes = allocate<AstNode *>(param_count); | |
| 22839 | 22851 | |
| 22840 | 22852 | for (size_t param_index = 0; param_index < param_count; param_index += 1) { |
| 22841 | 22853 | AstNode *param_node = proto_node->data.fn_proto.params.at(param_index); |
| ... | ... | @@ -22865,6 +22877,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 22865 | 22877 | if (param_type_val == nullptr) |
| 22866 | 22878 | return ira->codegen->invalid_instruction; |
| 22867 | 22879 | lazy_fn_type->param_types[param_index] = param_type_val; |
| 22880 | lazy_fn_type->param_type_src_nodes[param_index] = instruction->param_types[param_index]->source_node; | |
| 22868 | 22881 | } |
| 22869 | 22882 | |
| 22870 | 22883 | if (instruction->align_value != nullptr) { |
| ... | ... | @@ -22876,6 +22889,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 22876 | 22889 | lazy_fn_type->return_type = ir_resolve_const(ira, instruction->return_type->child, LazyOk); |
| 22877 | 22890 | if (lazy_fn_type->return_type == nullptr) |
| 22878 | 22891 | return ira->codegen->invalid_instruction; |
| 22892 | lazy_fn_type->return_type_src_node = instruction->return_type->source_node; | |
| 22879 | 22893 | |
| 22880 | 22894 | return result; |
| 22881 | 22895 | } |
| ... | ... | @@ -25187,7 +25201,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 25187 | 25201 | } else { |
| 25188 | 25202 | new_exec->first_err_trace_msg = ira->codegen->trace_err; |
| 25189 | 25203 | } |
| 25190 | if (new_exec->first_err_trace_msg != nullptr) { | |
| 25204 | if (new_exec->first_err_trace_msg != nullptr && | |
| 25205 | !old_instruction->source_node->already_traced_this_node) | |
| 25206 | { | |
| 25207 | old_instruction->source_node->already_traced_this_node = true; | |
| 25191 | 25208 | new_exec->first_err_trace_msg = add_error_note(ira->codegen, new_exec->first_err_trace_msg, |
| 25192 | 25209 | old_instruction->source_node, buf_create_from_str("referenced here")); |
| 25193 | 25210 | } |
| ... | ... | @@ -25204,7 +25221,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 25204 | 25221 | |
| 25205 | 25222 | if (new_exec->first_err_trace_msg != nullptr) { |
| 25206 | 25223 | codegen->trace_err = new_exec->first_err_trace_msg; |
| 25207 | if (codegen->trace_err != nullptr) { | |
| 25224 | if (codegen->trace_err != nullptr && new_exec->source_node != nullptr && | |
| 25225 | !new_exec->source_node->already_traced_this_node) | |
| 25226 | { | |
| 25227 | new_exec->source_node->already_traced_this_node = true; | |
| 25208 | 25228 | codegen->trace_err = add_error_note(codegen, codegen->trace_err, |
| 25209 | 25229 | new_exec->source_node, buf_create_from_str("referenced here")); |
| 25210 | 25230 | } |
| ... | ... | @@ -25435,14 +25455,15 @@ static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, As |
| 25435 | 25455 | param_info->type = nullptr; |
| 25436 | 25456 | return get_generic_fn_type(codegen, &fn_type_id); |
| 25437 | 25457 | } else { |
| 25438 | ZigType *param_type = ir_resolve_const_type(codegen, exec, source_node, | |
| 25458 | AstNode *param_src_node = lazy_fn_type->param_type_src_nodes[fn_type_id.next_param_index]; | |
| 25459 | ZigType *param_type = ir_resolve_const_type(codegen, exec, param_src_node, | |
| 25439 | 25460 | lazy_fn_type->param_types[fn_type_id.next_param_index]); |
| 25440 | 25461 | if (type_is_invalid(param_type)) |
| 25441 | 25462 | return nullptr; |
| 25442 | 25463 | switch (type_requires_comptime(codegen, param_type)) { |
| 25443 | 25464 | case ReqCompTimeYes: |
| 25444 | 25465 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 25445 | exec_add_error_node(codegen, exec, source_node, | |
| 25466 | exec_add_error_node(codegen, exec, param_src_node, | |
| 25446 | 25467 | buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'", |
| 25447 | 25468 | buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc))); |
| 25448 | 25469 | return nullptr; |
| ... | ... | @@ -25459,7 +25480,7 @@ static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, As |
| 25459 | 25480 | if ((err = type_resolve(codegen, param_type, ResolveStatusZeroBitsKnown))) |
| 25460 | 25481 | return nullptr; |
| 25461 | 25482 | if (!type_has_bits(param_type)) { |
| 25462 | exec_add_error_node(codegen, exec, source_node, | |
| 25483 | exec_add_error_node(codegen, exec, param_src_node, | |
| 25463 | 25484 | buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'", |
| 25464 | 25485 | buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc))); |
| 25465 | 25486 | return nullptr; |
| ... | ... | @@ -25474,11 +25495,13 @@ static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, As |
| 25474 | 25495 | return nullptr; |
| 25475 | 25496 | } |
| 25476 | 25497 | |
| 25477 | fn_type_id.return_type = ir_resolve_const_type(codegen, exec, source_node, lazy_fn_type->return_type); | |
| 25498 | fn_type_id.return_type = ir_resolve_const_type(codegen, exec, lazy_fn_type->return_type_src_node, | |
| 25499 | lazy_fn_type->return_type); | |
| 25478 | 25500 | if (type_is_invalid(fn_type_id.return_type)) |
| 25479 | 25501 | return nullptr; |
| 25480 | 25502 | if (fn_type_id.return_type->id == ZigTypeIdOpaque) { |
| 25481 | exec_add_error_node(codegen, exec, source_node, buf_create_from_str("return type cannot be opaque")); | |
| 25503 | exec_add_error_node(codegen, exec, lazy_fn_type->return_type_src_node, | |
| 25504 | buf_create_from_str("return type cannot be opaque")); | |
| 25482 | 25505 | return nullptr; |
| 25483 | 25506 | } |
| 25484 | 25507 | |
| ... | ... | @@ -25653,11 +25676,15 @@ static Error ir_resolve_lazy_raw(CodeGen *codegen, AstNode *source_node, ConstEx |
| 25653 | 25676 | Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ConstExprValue *val) { |
| 25654 | 25677 | Error err; |
| 25655 | 25678 | if ((err = ir_resolve_lazy_raw(codegen, source_node, val))) { |
| 25656 | if (codegen->trace_err != nullptr) { | |
| 25679 | if (codegen->trace_err != nullptr && !source_node->already_traced_this_node) { | |
| 25680 | source_node->already_traced_this_node = true; | |
| 25657 | 25681 | codegen->trace_err = add_error_note(codegen, codegen->trace_err, source_node, |
| 25658 | 25682 | buf_create_from_str("referenced here")); |
| 25659 | 25683 | } |
| 25660 | 25684 | return err; |
| 25661 | 25685 | } |
| 25686 | if (type_is_invalid(val->type)) { | |
| 25687 | return ErrorSemanticAnalyzeFail; | |
| 25688 | } | |
| 25662 | 25689 | return ErrorNone; |
| 25663 | 25690 | } |
test/compile_errors.zig+37-35| ... | ... | @@ -481,7 +481,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 481 | 481 | \\} |
| 482 | 482 | , |
| 483 | 483 | "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches", |
| 484 | "tmp.zig:1:29: note: called from here", | |
| 484 | "tmp.zig:1:29: note: referenced here", | |
| 485 | "tmp.zig:5:18: note: referenced here", | |
| 485 | 486 | ); |
| 486 | 487 | |
| 487 | 488 | cases.add( |
| ... | ... | @@ -645,7 +646,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 645 | 646 | \\const A = struct { a : A, }; |
| 646 | 647 | \\export fn entry() usize { return @sizeOf(A); } |
| 647 | 648 | , |
| 648 | "tmp.zig:1:11: error: struct 'A' contains itself", | |
| 649 | "tmp.zig:1:11: error: struct 'A' depends on itself", | |
| 649 | 650 | ); |
| 650 | 651 | |
| 651 | 652 | cases.add( |
| ... | ... | @@ -655,7 +656,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 655 | 656 | \\const C = struct { a : A, }; |
| 656 | 657 | \\export fn entry() usize { return @sizeOf(A); } |
| 657 | 658 | , |
| 658 | "tmp.zig:1:11: error: struct 'A' contains itself", | |
| 659 | "tmp.zig:1:11: error: struct 'A' depends on itself", | |
| 659 | 660 | ); |
| 660 | 661 | |
| 661 | 662 | cases.add( |
| ... | ... | @@ -670,7 +671,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 670 | 671 | \\ return @sizeOf(@typeOf(foo.x)); |
| 671 | 672 | \\} |
| 672 | 673 | , |
| 673 | "tmp.zig:1:13: error: struct 'Foo' contains itself", | |
| 674 | "tmp.zig:1:13: error: struct 'Foo' depends on itself", | |
| 674 | 675 | "tmp.zig:8:28: note: referenced here", |
| 675 | 676 | ); |
| 676 | 677 | |
| ... | ... | @@ -689,7 +690,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 689 | 690 | \\} |
| 690 | 691 | , |
| 691 | 692 | "tmp.zig:7:9: error: dependency loop detected", |
| 692 | "tmp.zig:2:19: note: called from here", | |
| 693 | "tmp.zig:2:19: note: referenced here", | |
| 693 | 694 | "tmp.zig:10:21: note: referenced here", |
| 694 | 695 | ); |
| 695 | 696 | |
| ... | ... | @@ -703,7 +704,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 703 | 704 | \\ var s: Foo = Foo.E; |
| 704 | 705 | \\} |
| 705 | 706 | , |
| 706 | "tmp.zig:1:17: error: 'Foo' depends on itself", | |
| 707 | "tmp.zig:1:17: error: enum 'Foo' depends on itself", | |
| 707 | 708 | ); |
| 708 | 709 | |
| 709 | 710 | cases.add( |
| ... | ... | @@ -866,7 +867,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 866 | 867 | break :x tc; |
| 867 | 868 | }); |
| 868 | 869 | |
| 869 | cases.addTest( | |
| 870 | cases.add( | |
| 870 | 871 | "export generic function", |
| 871 | 872 | \\export fn foo(num: var) i32 { |
| 872 | 873 | \\ return 0; |
| ... | ... | @@ -875,17 +876,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 875 | 876 | "tmp.zig:1:15: error: parameter of type 'var' not allowed in function with calling convention 'ccc'", |
| 876 | 877 | ); |
| 877 | 878 | |
| 878 | cases.addTest( | |
| 879 | cases.add( | |
| 879 | 880 | "C pointer to c_void", |
| 880 | 881 | \\export fn a() void { |
| 881 | 882 | \\ var x: *c_void = undefined; |
| 882 | 883 | \\ var y: [*c]c_void = x; |
| 883 | 884 | \\} |
| 884 | 885 | , |
| 885 | "tmp.zig:3:12: error: C pointers cannot point opaque types", | |
| 886 | "tmp.zig:3:16: error: C pointers cannot point opaque types", | |
| 886 | 887 | ); |
| 887 | 888 | |
| 888 | cases.addTest( | |
| 889 | cases.add( | |
| 889 | 890 | "directly embedding opaque type in struct and union", |
| 890 | 891 | \\const O = @OpaqueType(); |
| 891 | 892 | \\const Foo = struct { |
| ... | ... | @@ -906,7 +907,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 906 | 907 | "tmp.zig:7:10: error: opaque types have unknown size and therefore cannot be directly embedded in unions", |
| 907 | 908 | ); |
| 908 | 909 | |
| 909 | cases.addTest( | |
| 910 | cases.add( | |
| 910 | 911 | "implicit cast between C pointer and Zig pointer - bad const/align/child", |
| 911 | 912 | \\export fn a() void { |
| 912 | 913 | \\ var x: [*c]u8 = undefined; |
| ... | ... | @@ -942,7 +943,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 942 | 943 | "tmp.zig:23:22: error: expected type '[*c]u32', found '*u8'", |
| 943 | 944 | ); |
| 944 | 945 | |
| 945 | cases.addTest( | |
| 946 | cases.add( | |
| 946 | 947 | "implicit casting null c pointer to zig pointer", |
| 947 | 948 | \\comptime { |
| 948 | 949 | \\ var c_ptr: [*c]u8 = 0; |
| ... | ... | @@ -952,7 +953,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 952 | 953 | "tmp.zig:3:24: error: null pointer casted to type '*u8'", |
| 953 | 954 | ); |
| 954 | 955 | |
| 955 | cases.addTest( | |
| 956 | cases.add( | |
| 956 | 957 | "implicit casting undefined c pointer to zig pointer", |
| 957 | 958 | \\comptime { |
| 958 | 959 | \\ var c_ptr: [*c]u8 = undefined; |
| ... | ... | @@ -962,7 +963,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 962 | 963 | "tmp.zig:3:24: error: use of undefined value here causes undefined behavior", |
| 963 | 964 | ); |
| 964 | 965 | |
| 965 | cases.addTest( | |
| 966 | cases.add( | |
| 966 | 967 | "implicit casting C pointers which would mess up null semantics", |
| 967 | 968 | \\export fn entry() void { |
| 968 | 969 | \\ var slice: []const u8 = "aoeu"; |
| ... | ... | @@ -987,7 +988,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 987 | 988 | "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'", |
| 988 | 989 | ); |
| 989 | 990 | |
| 990 | cases.addTest( | |
| 991 | cases.add( | |
| 991 | 992 | "implicit casting too big integers to C pointers", |
| 992 | 993 | \\export fn a() void { |
| 993 | 994 | \\ var ptr: [*c]u8 = (1 << 64) + 1; |
| ... | ... | @@ -1001,14 +1002,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1001 | 1002 | "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", |
| 1002 | 1003 | ); |
| 1003 | 1004 | |
| 1004 | cases.addTest( | |
| 1005 | cases.add( | |
| 1005 | 1006 | "C pointer pointing to non C ABI compatible type or has align attr", |
| 1006 | 1007 | \\const Foo = struct {}; |
| 1007 | 1008 | \\export fn a() void { |
| 1008 | 1009 | \\ const T = [*c]Foo; |
| 1009 | 1010 | \\} |
| 1010 | 1011 | , |
| 1011 | "tmp.zig:3:15: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", | |
| 1012 | "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", | |
| 1012 | 1013 | ); |
| 1013 | 1014 | |
| 1014 | 1015 | cases.addCase(x: { |
| ... | ... | @@ -1029,7 +1030,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1029 | 1030 | break :x tc; |
| 1030 | 1031 | }); |
| 1031 | 1032 | |
| 1032 | cases.addTest( | |
| 1033 | cases.add( | |
| 1033 | 1034 | "assign to invalid dereference", |
| 1034 | 1035 | \\export fn entry() void { |
| 1035 | 1036 | \\ 'a'.* = 1; |
| ... | ... | @@ -1038,7 +1039,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1038 | 1039 | "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'", |
| 1039 | 1040 | ); |
| 1040 | 1041 | |
| 1041 | cases.addTest( | |
| 1042 | cases.add( | |
| 1042 | 1043 | "take slice of invalid dereference", |
| 1043 | 1044 | \\export fn entry() void { |
| 1044 | 1045 | \\ const x = 'a'.*[0..]; |
| ... | ... | @@ -1047,7 +1048,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1047 | 1048 | "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'", |
| 1048 | 1049 | ); |
| 1049 | 1050 | |
| 1050 | cases.addTest( | |
| 1051 | cases.add( | |
| 1051 | 1052 | "@truncate undefined value", |
| 1052 | 1053 | \\export fn entry() void { |
| 1053 | 1054 | \\ var z = @truncate(u8, u16(undefined)); |
| ... | ... | @@ -1935,7 +1936,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1935 | 1936 | "unknown length pointer to opaque", |
| 1936 | 1937 | \\export const T = [*]@OpaqueType(); |
| 1937 | 1938 | , |
| 1938 | "tmp.zig:1:18: error: unknown-length pointer to opaque", | |
| 1939 | "tmp.zig:1:21: error: unknown-length pointer to opaque", | |
| 1939 | 1940 | ); |
| 1940 | 1941 | |
| 1941 | 1942 | cases.add( |
| ... | ... | @@ -2924,7 +2925,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2924 | 2925 | \\fn a() *noreturn {} |
| 2925 | 2926 | \\export fn entry() void { _ = a(); } |
| 2926 | 2927 | , |
| 2927 | "tmp.zig:1:8: error: pointer to noreturn not allowed", | |
| 2928 | "tmp.zig:1:9: error: pointer to noreturn not allowed", | |
| 2928 | 2929 | ); |
| 2929 | 2930 | |
| 2930 | 2931 | cases.add( |
| ... | ... | @@ -3606,8 +3607,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3606 | 3607 | \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); } |
| 3607 | 3608 | , |
| 3608 | 3609 | "tmp.zig:5:25: error: unable to evaluate constant expression", |
| 3609 | "tmp.zig:2:12: note: called from here", | |
| 3610 | "tmp.zig:2:8: note: called from here", | |
| 3610 | "tmp.zig:2:12: note: referenced here", | |
| 3611 | "tmp.zig:2:8: note: referenced here", | |
| 3611 | 3612 | ); |
| 3612 | 3613 | |
| 3613 | 3614 | cases.add( |
| ... | ... | @@ -3701,7 +3702,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3701 | 3702 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 3702 | 3703 | , |
| 3703 | 3704 | "tmp.zig:3:14: error: division by zero", |
| 3704 | "tmp.zig:1:14: note: called from here", | |
| 3705 | "tmp.zig:1:14: note: referenced here", | |
| 3705 | 3706 | ); |
| 3706 | 3707 | |
| 3707 | 3708 | cases.add( |
| ... | ... | @@ -4133,7 +4134,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4133 | 4134 | \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); } |
| 4134 | 4135 | , |
| 4135 | 4136 | "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches", |
| 4136 | "tmp.zig:3:21: note: called from here", | |
| 4137 | "tmp.zig:1:37: note: referenced here", | |
| 4138 | "tmp.zig:6:50: note: referenced here", | |
| 4137 | 4139 | ); |
| 4138 | 4140 | |
| 4139 | 4141 | cases.add( |
| ... | ... | @@ -4174,7 +4176,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4174 | 4176 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 4175 | 4177 | , |
| 4176 | 4178 | "tmp.zig:6:26: error: unable to evaluate constant expression", |
| 4177 | "tmp.zig:4:17: note: called from here", | |
| 4179 | "tmp.zig:4:17: note: referenced here", | |
| 4178 | 4180 | ); |
| 4179 | 4181 | |
| 4180 | 4182 | cases.add( |
| ... | ... | @@ -4257,7 +4259,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4257 | 4259 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4258 | 4260 | , |
| 4259 | 4261 | "tmp.zig:3:12: error: negation caused overflow", |
| 4260 | "tmp.zig:1:14: note: called from here", | |
| 4262 | "tmp.zig:1:14: note: referenced here", | |
| 4261 | 4263 | ); |
| 4262 | 4264 | |
| 4263 | 4265 | cases.add( |
| ... | ... | @@ -4270,7 +4272,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4270 | 4272 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4271 | 4273 | , |
| 4272 | 4274 | "tmp.zig:3:14: error: operation caused overflow", |
| 4273 | "tmp.zig:1:14: note: called from here", | |
| 4275 | "tmp.zig:1:14: note: referenced here", | |
| 4274 | 4276 | ); |
| 4275 | 4277 | |
| 4276 | 4278 | cases.add( |
| ... | ... | @@ -4283,7 +4285,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4283 | 4285 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4284 | 4286 | , |
| 4285 | 4287 | "tmp.zig:3:14: error: operation caused overflow", |
| 4286 | "tmp.zig:1:14: note: called from here", | |
| 4288 | "tmp.zig:1:14: note: referenced here", | |
| 4287 | 4289 | ); |
| 4288 | 4290 | |
| 4289 | 4291 | cases.add( |
| ... | ... | @@ -4296,7 +4298,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4296 | 4298 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4297 | 4299 | , |
| 4298 | 4300 | "tmp.zig:3:14: error: operation caused overflow", |
| 4299 | "tmp.zig:1:14: note: called from here", | |
| 4301 | "tmp.zig:1:14: note: referenced here", | |
| 4300 | 4302 | ); |
| 4301 | 4303 | |
| 4302 | 4304 | cases.add( |
| ... | ... | @@ -4388,7 +4390,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4388 | 4390 | \\} |
| 4389 | 4391 | , |
| 4390 | 4392 | "tmp.zig:3:7: error: unable to evaluate constant expression", |
| 4391 | "tmp.zig:16:19: note: called from here", | |
| 4393 | "tmp.zig:16:19: note: referenced here", | |
| 4392 | 4394 | ); |
| 4393 | 4395 | |
| 4394 | 4396 | cases.add( |
| ... | ... | @@ -4618,7 +4620,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4618 | 4620 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 4619 | 4621 | , |
| 4620 | 4622 | "tmp.zig:2:26: error: index 1 outside argument list of size 1", |
| 4621 | "tmp.zig:6:15: note: called from here", | |
| 4623 | "tmp.zig:6:15: note: referenced here", | |
| 4622 | 4624 | ); |
| 4623 | 4625 | |
| 4624 | 4626 | cases.add( |
| ... | ... | @@ -4717,7 +4719,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4717 | 4719 | \\} |
| 4718 | 4720 | , |
| 4719 | 4721 | "tmp.zig:10:14: error: unable to evaluate constant expression", |
| 4720 | "tmp.zig:6:20: note: called from here", | |
| 4722 | "tmp.zig:6:20: note: referenced here", | |
| 4721 | 4723 | ); |
| 4722 | 4724 | |
| 4723 | 4725 | cases.add( |
| ... | ... | @@ -5864,7 +5866,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5864 | 5866 | \\} |
| 5865 | 5867 | , |
| 5866 | 5868 | "tmp.zig:4:25: error: aoeu", |
| 5867 | "tmp.zig:1:36: note: called from here", | |
| 5869 | "tmp.zig:1:36: note: referenced here", | |
| 5868 | 5870 | "tmp.zig:12:20: note: referenced here", |
| 5869 | 5871 | ); |
| 5870 | 5872 |