| ... | ... | @@ -622,197 +622,197 @@ pub fn addCases(ctx: *TestContext) !void { |
| 622 | 622 | ); |
| 623 | 623 | |
| 624 | 624 | // Labeled blocks (no conditional branch) |
| 625 | | case.addCompareOutput( |
| 626 | | \\export fn _start() noreturn { |
| 627 | | \\ assert(add(3, 4) == 20); |
| 628 | | \\ |
| 629 | | \\ exit(); |
| 630 | | \\} |
| 631 | | \\ |
| 632 | | \\fn add(a: u32, b: u32) u32 { |
| 633 | | \\ const x: u32 = blk: { |
| 634 | | \\ const c = a + b; // 7 |
| 635 | | \\ const d = a + c; // 10 |
| 636 | | \\ const e = d + b; // 14 |
| 637 | | \\ break :blk e; |
| 638 | | \\ }; |
| 639 | | \\ const y = x + a; // 17 |
| 640 | | \\ const z = y + a; // 20 |
| 641 | | \\ return z; |
| 642 | | \\} |
| 643 | | \\ |
| 644 | | \\pub fn assert(ok: bool) void { |
| 645 | | \\ if (!ok) unreachable; // assertion failure |
| 646 | | \\} |
| 647 | | \\ |
| 648 | | \\fn exit() noreturn { |
| 649 | | \\ asm volatile ("syscall" |
| 650 | | \\ : |
| 651 | | \\ : [number] "{rax}" (231), |
| 652 | | \\ [arg1] "{rdi}" (0) |
| 653 | | \\ : "rcx", "r11", "memory" |
| 654 | | \\ ); |
| 655 | | \\ unreachable; |
| 656 | | \\} |
| 657 | | , |
| 658 | | "", |
| 659 | | ); |
| 625 | //case.addCompareOutput( |
| 626 | // \\export fn _start() noreturn { |
| 627 | // \\ assert(add(3, 4) == 20); |
| 628 | // \\ |
| 629 | // \\ exit(); |
| 630 | // \\} |
| 631 | // \\ |
| 632 | // \\fn add(a: u32, b: u32) u32 { |
| 633 | // \\ const x: u32 = blk: { |
| 634 | // \\ const c = a + b; // 7 |
| 635 | // \\ const d = a + c; // 10 |
| 636 | // \\ const e = d + b; // 14 |
| 637 | // \\ break :blk e; |
| 638 | // \\ }; |
| 639 | // \\ const y = x + a; // 17 |
| 640 | // \\ const z = y + a; // 20 |
| 641 | // \\ return z; |
| 642 | // \\} |
| 643 | // \\ |
| 644 | // \\pub fn assert(ok: bool) void { |
| 645 | // \\ if (!ok) unreachable; // assertion failure |
| 646 | // \\} |
| 647 | // \\ |
| 648 | // \\fn exit() noreturn { |
| 649 | // \\ asm volatile ("syscall" |
| 650 | // \\ : |
| 651 | // \\ : [number] "{rax}" (231), |
| 652 | // \\ [arg1] "{rdi}" (0) |
| 653 | // \\ : "rcx", "r11", "memory" |
| 654 | // \\ ); |
| 655 | // \\ unreachable; |
| 656 | // \\} |
| 657 | //, |
| 658 | // "", |
| 659 | //); |
| 660 | 660 | |
| 661 | 661 | // This catches a possible bug in the logic for re-using dying operands. |
| 662 | | case.addCompareOutput( |
| 663 | | \\export fn _start() noreturn { |
| 664 | | \\ assert(add(3, 4) == 116); |
| 665 | | \\ |
| 666 | | \\ exit(); |
| 667 | | \\} |
| 668 | | \\ |
| 669 | | \\fn add(a: u32, b: u32) u32 { |
| 670 | | \\ const x: u32 = blk: { |
| 671 | | \\ const c = a + b; // 7 |
| 672 | | \\ const d = a + c; // 10 |
| 673 | | \\ const e = d + b; // 14 |
| 674 | | \\ const f = d + e; // 24 |
| 675 | | \\ const g = e + f; // 38 |
| 676 | | \\ const h = f + g; // 62 |
| 677 | | \\ const i = g + h; // 100 |
| 678 | | \\ const j = i + d; // 110 |
| 679 | | \\ break :blk j; |
| 680 | | \\ }; |
| 681 | | \\ const y = x + a; // 113 |
| 682 | | \\ const z = y + a; // 116 |
| 683 | | \\ return z; |
| 684 | | \\} |
| 685 | | \\ |
| 686 | | \\pub fn assert(ok: bool) void { |
| 687 | | \\ if (!ok) unreachable; // assertion failure |
| 688 | | \\} |
| 689 | | \\ |
| 690 | | \\fn exit() noreturn { |
| 691 | | \\ asm volatile ("syscall" |
| 692 | | \\ : |
| 693 | | \\ : [number] "{rax}" (231), |
| 694 | | \\ [arg1] "{rdi}" (0) |
| 695 | | \\ : "rcx", "r11", "memory" |
| 696 | | \\ ); |
| 697 | | \\ unreachable; |
| 698 | | \\} |
| 699 | | , |
| 700 | | "", |
| 701 | | ); |
| 662 | //case.addCompareOutput( |
| 663 | // \\export fn _start() noreturn { |
| 664 | // \\ assert(add(3, 4) == 116); |
| 665 | // \\ |
| 666 | // \\ exit(); |
| 667 | // \\} |
| 668 | // \\ |
| 669 | // \\fn add(a: u32, b: u32) u32 { |
| 670 | // \\ const x: u32 = blk: { |
| 671 | // \\ const c = a + b; // 7 |
| 672 | // \\ const d = a + c; // 10 |
| 673 | // \\ const e = d + b; // 14 |
| 674 | // \\ const f = d + e; // 24 |
| 675 | // \\ const g = e + f; // 38 |
| 676 | // \\ const h = f + g; // 62 |
| 677 | // \\ const i = g + h; // 100 |
| 678 | // \\ const j = i + d; // 110 |
| 679 | // \\ break :blk j; |
| 680 | // \\ }; |
| 681 | // \\ const y = x + a; // 113 |
| 682 | // \\ const z = y + a; // 116 |
| 683 | // \\ return z; |
| 684 | // \\} |
| 685 | // \\ |
| 686 | // \\pub fn assert(ok: bool) void { |
| 687 | // \\ if (!ok) unreachable; // assertion failure |
| 688 | // \\} |
| 689 | // \\ |
| 690 | // \\fn exit() noreturn { |
| 691 | // \\ asm volatile ("syscall" |
| 692 | // \\ : |
| 693 | // \\ : [number] "{rax}" (231), |
| 694 | // \\ [arg1] "{rdi}" (0) |
| 695 | // \\ : "rcx", "r11", "memory" |
| 696 | // \\ ); |
| 697 | // \\ unreachable; |
| 698 | // \\} |
| 699 | //, |
| 700 | // "", |
| 701 | //); |
| 702 | 702 | |
| 703 | 703 | // Spilling registers to the stack. |
| 704 | | case.addCompareOutput( |
| 705 | | \\export fn _start() noreturn { |
| 706 | | \\ assert(add(3, 4) == 791); |
| 707 | | \\ |
| 708 | | \\ exit(); |
| 709 | | \\} |
| 710 | | \\ |
| 711 | | \\fn add(a: u32, b: u32) u32 { |
| 712 | | \\ const x: u32 = blk: { |
| 713 | | \\ const c = a + b; // 7 |
| 714 | | \\ const d = a + c; // 10 |
| 715 | | \\ const e = d + b; // 14 |
| 716 | | \\ const f = d + e; // 24 |
| 717 | | \\ const g = e + f; // 38 |
| 718 | | \\ const h = f + g; // 62 |
| 719 | | \\ const i = g + h; // 100 |
| 720 | | \\ const j = i + d; // 110 |
| 721 | | \\ const k = i + j; // 210 |
| 722 | | \\ const l = k + c; // 217 |
| 723 | | \\ const m = l + d; // 227 |
| 724 | | \\ const n = m + e; // 241 |
| 725 | | \\ const o = n + f; // 265 |
| 726 | | \\ const p = o + g; // 303 |
| 727 | | \\ const q = p + h; // 365 |
| 728 | | \\ const r = q + i; // 465 |
| 729 | | \\ const s = r + j; // 575 |
| 730 | | \\ const t = s + k; // 785 |
| 731 | | \\ break :blk t; |
| 732 | | \\ }; |
| 733 | | \\ const y = x + a; // 788 |
| 734 | | \\ const z = y + a; // 791 |
| 735 | | \\ return z; |
| 736 | | \\} |
| 737 | | \\ |
| 738 | | \\pub fn assert(ok: bool) void { |
| 739 | | \\ if (!ok) unreachable; // assertion failure |
| 740 | | \\} |
| 741 | | \\ |
| 742 | | \\fn exit() noreturn { |
| 743 | | \\ asm volatile ("syscall" |
| 744 | | \\ : |
| 745 | | \\ : [number] "{rax}" (231), |
| 746 | | \\ [arg1] "{rdi}" (0) |
| 747 | | \\ : "rcx", "r11", "memory" |
| 748 | | \\ ); |
| 749 | | \\ unreachable; |
| 750 | | \\} |
| 751 | | , |
| 752 | | "", |
| 753 | | ); |
| 704 | //case.addCompareOutput( |
| 705 | // \\export fn _start() noreturn { |
| 706 | // \\ assert(add(3, 4) == 791); |
| 707 | // \\ |
| 708 | // \\ exit(); |
| 709 | // \\} |
| 710 | // \\ |
| 711 | // \\fn add(a: u32, b: u32) u32 { |
| 712 | // \\ const x: u32 = blk: { |
| 713 | // \\ const c = a + b; // 7 |
| 714 | // \\ const d = a + c; // 10 |
| 715 | // \\ const e = d + b; // 14 |
| 716 | // \\ const f = d + e; // 24 |
| 717 | // \\ const g = e + f; // 38 |
| 718 | // \\ const h = f + g; // 62 |
| 719 | // \\ const i = g + h; // 100 |
| 720 | // \\ const j = i + d; // 110 |
| 721 | // \\ const k = i + j; // 210 |
| 722 | // \\ const l = k + c; // 217 |
| 723 | // \\ const m = l + d; // 227 |
| 724 | // \\ const n = m + e; // 241 |
| 725 | // \\ const o = n + f; // 265 |
| 726 | // \\ const p = o + g; // 303 |
| 727 | // \\ const q = p + h; // 365 |
| 728 | // \\ const r = q + i; // 465 |
| 729 | // \\ const s = r + j; // 575 |
| 730 | // \\ const t = s + k; // 785 |
| 731 | // \\ break :blk t; |
| 732 | // \\ }; |
| 733 | // \\ const y = x + a; // 788 |
| 734 | // \\ const z = y + a; // 791 |
| 735 | // \\ return z; |
| 736 | // \\} |
| 737 | // \\ |
| 738 | // \\pub fn assert(ok: bool) void { |
| 739 | // \\ if (!ok) unreachable; // assertion failure |
| 740 | // \\} |
| 741 | // \\ |
| 742 | // \\fn exit() noreturn { |
| 743 | // \\ asm volatile ("syscall" |
| 744 | // \\ : |
| 745 | // \\ : [number] "{rax}" (231), |
| 746 | // \\ [arg1] "{rdi}" (0) |
| 747 | // \\ : "rcx", "r11", "memory" |
| 748 | // \\ ); |
| 749 | // \\ unreachable; |
| 750 | // \\} |
| 751 | //, |
| 752 | // "", |
| 753 | //); |
| 754 | 754 | |
| 755 | 755 | // Reusing the registers of dead operands playing nicely with conditional branching. |
| 756 | | case.addCompareOutput( |
| 757 | | \\export fn _start() noreturn { |
| 758 | | \\ assert(add(3, 4) == 791); |
| 759 | | \\ assert(add(4, 3) == 79); |
| 760 | | \\ |
| 761 | | \\ exit(); |
| 762 | | \\} |
| 763 | | \\ |
| 764 | | \\fn add(a: u32, b: u32) u32 { |
| 765 | | \\ const x: u32 = if (a < b) blk: { |
| 766 | | \\ const c = a + b; // 7 |
| 767 | | \\ const d = a + c; // 10 |
| 768 | | \\ const e = d + b; // 14 |
| 769 | | \\ const f = d + e; // 24 |
| 770 | | \\ const g = e + f; // 38 |
| 771 | | \\ const h = f + g; // 62 |
| 772 | | \\ const i = g + h; // 100 |
| 773 | | \\ const j = i + d; // 110 |
| 774 | | \\ const k = i + j; // 210 |
| 775 | | \\ const l = k + c; // 217 |
| 776 | | \\ const m = l + d; // 227 |
| 777 | | \\ const n = m + e; // 241 |
| 778 | | \\ const o = n + f; // 265 |
| 779 | | \\ const p = o + g; // 303 |
| 780 | | \\ const q = p + h; // 365 |
| 781 | | \\ const r = q + i; // 465 |
| 782 | | \\ const s = r + j; // 575 |
| 783 | | \\ const t = s + k; // 785 |
| 784 | | \\ break :blk t; |
| 785 | | \\ } else blk: { |
| 786 | | \\ const t = b + b + a; // 10 |
| 787 | | \\ const c = a + t; // 14 |
| 788 | | \\ const d = c + t; // 24 |
| 789 | | \\ const e = d + t; // 34 |
| 790 | | \\ const f = e + t; // 44 |
| 791 | | \\ const g = f + t; // 54 |
| 792 | | \\ const h = c + g; // 68 |
| 793 | | \\ break :blk h + b; // 71 |
| 794 | | \\ }; |
| 795 | | \\ const y = x + a; // 788, 75 |
| 796 | | \\ const z = y + a; // 791, 79 |
| 797 | | \\ return z; |
| 798 | | \\} |
| 799 | | \\ |
| 800 | | \\pub fn assert(ok: bool) void { |
| 801 | | \\ if (!ok) unreachable; // assertion failure |
| 802 | | \\} |
| 803 | | \\ |
| 804 | | \\fn exit() noreturn { |
| 805 | | \\ asm volatile ("syscall" |
| 806 | | \\ : |
| 807 | | \\ : [number] "{rax}" (231), |
| 808 | | \\ [arg1] "{rdi}" (0) |
| 809 | | \\ : "rcx", "r11", "memory" |
| 810 | | \\ ); |
| 811 | | \\ unreachable; |
| 812 | | \\} |
| 813 | | , |
| 814 | | "", |
| 815 | | ); |
| 756 | //case.addCompareOutput( |
| 757 | // \\export fn _start() noreturn { |
| 758 | // \\ assert(add(3, 4) == 791); |
| 759 | // \\ assert(add(4, 3) == 79); |
| 760 | // \\ |
| 761 | // \\ exit(); |
| 762 | // \\} |
| 763 | // \\ |
| 764 | // \\fn add(a: u32, b: u32) u32 { |
| 765 | // \\ const x: u32 = if (a < b) blk: { |
| 766 | // \\ const c = a + b; // 7 |
| 767 | // \\ const d = a + c; // 10 |
| 768 | // \\ const e = d + b; // 14 |
| 769 | // \\ const f = d + e; // 24 |
| 770 | // \\ const g = e + f; // 38 |
| 771 | // \\ const h = f + g; // 62 |
| 772 | // \\ const i = g + h; // 100 |
| 773 | // \\ const j = i + d; // 110 |
| 774 | // \\ const k = i + j; // 210 |
| 775 | // \\ const l = k + c; // 217 |
| 776 | // \\ const m = l + d; // 227 |
| 777 | // \\ const n = m + e; // 241 |
| 778 | // \\ const o = n + f; // 265 |
| 779 | // \\ const p = o + g; // 303 |
| 780 | // \\ const q = p + h; // 365 |
| 781 | // \\ const r = q + i; // 465 |
| 782 | // \\ const s = r + j; // 575 |
| 783 | // \\ const t = s + k; // 785 |
| 784 | // \\ break :blk t; |
| 785 | // \\ } else blk: { |
| 786 | // \\ const t = b + b + a; // 10 |
| 787 | // \\ const c = a + t; // 14 |
| 788 | // \\ const d = c + t; // 24 |
| 789 | // \\ const e = d + t; // 34 |
| 790 | // \\ const f = e + t; // 44 |
| 791 | // \\ const g = f + t; // 54 |
| 792 | // \\ const h = c + g; // 68 |
| 793 | // \\ break :blk h + b; // 71 |
| 794 | // \\ }; |
| 795 | // \\ const y = x + a; // 788, 75 |
| 796 | // \\ const z = y + a; // 791, 79 |
| 797 | // \\ return z; |
| 798 | // \\} |
| 799 | // \\ |
| 800 | // \\pub fn assert(ok: bool) void { |
| 801 | // \\ if (!ok) unreachable; // assertion failure |
| 802 | // \\} |
| 803 | // \\ |
| 804 | // \\fn exit() noreturn { |
| 805 | // \\ asm volatile ("syscall" |
| 806 | // \\ : |
| 807 | // \\ : [number] "{rax}" (231), |
| 808 | // \\ [arg1] "{rdi}" (0) |
| 809 | // \\ : "rcx", "r11", "memory" |
| 810 | // \\ ); |
| 811 | // \\ unreachable; |
| 812 | // \\} |
| 813 | //, |
| 814 | // "", |
| 815 | //); |
| 816 | 816 | |
| 817 | 817 | // Character literals and multiline strings. |
| 818 | 818 | case.addCompareOutput( |
| ... | ... | @@ -880,29 +880,29 @@ pub fn addCases(ctx: *TestContext) !void { |
| 880 | 880 | ); |
| 881 | 881 | |
| 882 | 882 | // Array access. |
| 883 | | case.addCompareOutput( |
| 884 | | \\export fn _start() noreturn { |
| 885 | | \\ assert("hello"[0] == 'h'); |
| 886 | | \\ |
| 887 | | \\ exit(); |
| 888 | | \\} |
| 889 | | \\ |
| 890 | | \\pub fn assert(ok: bool) void { |
| 891 | | \\ if (!ok) unreachable; // assertion failure |
| 892 | | \\} |
| 893 | | \\ |
| 894 | | \\fn exit() noreturn { |
| 895 | | \\ asm volatile ("syscall" |
| 896 | | \\ : |
| 897 | | \\ : [number] "{rax}" (231), |
| 898 | | \\ [arg1] "{rdi}" (0) |
| 899 | | \\ : "rcx", "r11", "memory" |
| 900 | | \\ ); |
| 901 | | \\ unreachable; |
| 902 | | \\} |
| 903 | | , |
| 904 | | "", |
| 905 | | ); |
| 883 | //case.addCompareOutput( |
| 884 | // \\export fn _start() noreturn { |
| 885 | // \\ assert("hello"[0] == 'h'); |
| 886 | // \\ |
| 887 | // \\ exit(); |
| 888 | // \\} |
| 889 | // \\ |
| 890 | // \\pub fn assert(ok: bool) void { |
| 891 | // \\ if (!ok) unreachable; // assertion failure |
| 892 | // \\} |
| 893 | // \\ |
| 894 | // \\fn exit() noreturn { |
| 895 | // \\ asm volatile ("syscall" |
| 896 | // \\ : |
| 897 | // \\ : [number] "{rax}" (231), |
| 898 | // \\ [arg1] "{rdi}" (0) |
| 899 | // \\ : "rcx", "r11", "memory" |
| 900 | // \\ ); |
| 901 | // \\ unreachable; |
| 902 | // \\} |
| 903 | //, |
| 904 | // "", |
| 905 | //); |
| 906 | 906 | |
| 907 | 907 | // 64bit set stack |
| 908 | 908 | case.addCompareOutput( |
| ... | ... | @@ -931,76 +931,76 @@ pub fn addCases(ctx: *TestContext) !void { |
| 931 | 931 | ); |
| 932 | 932 | |
| 933 | 933 | // Basic for loop |
| 934 | | case.addCompareOutput( |
| 935 | | \\export fn _start() noreturn { |
| 936 | | \\ for ("hello") |_| print(); |
| 937 | | \\ |
| 938 | | \\ exit(); |
| 939 | | \\} |
| 940 | | \\ |
| 941 | | \\fn print() void { |
| 942 | | \\ asm volatile ("syscall" |
| 943 | | \\ : |
| 944 | | \\ : [number] "{rax}" (1), |
| 945 | | \\ [arg1] "{rdi}" (1), |
| 946 | | \\ [arg2] "{rsi}" (@ptrToInt("hello\n")), |
| 947 | | \\ [arg3] "{rdx}" (6) |
| 948 | | \\ : "rcx", "r11", "memory" |
| 949 | | \\ ); |
| 950 | | \\ return; |
| 951 | | \\} |
| 952 | | \\ |
| 953 | | \\fn exit() noreturn { |
| 954 | | \\ asm volatile ("syscall" |
| 955 | | \\ : |
| 956 | | \\ : [number] "{rax}" (231), |
| 957 | | \\ [arg1] "{rdi}" (0) |
| 958 | | \\ : "rcx", "r11", "memory" |
| 959 | | \\ ); |
| 960 | | \\ unreachable; |
| 961 | | \\} |
| 962 | | , |
| 963 | | "hello\nhello\nhello\nhello\nhello\n", |
| 964 | | ); |
| 934 | //case.addCompareOutput( |
| 935 | // \\export fn _start() noreturn { |
| 936 | // \\ for ("hello") |_| print(); |
| 937 | // \\ |
| 938 | // \\ exit(); |
| 939 | // \\} |
| 940 | // \\ |
| 941 | // \\fn print() void { |
| 942 | // \\ asm volatile ("syscall" |
| 943 | // \\ : |
| 944 | // \\ : [number] "{rax}" (1), |
| 945 | // \\ [arg1] "{rdi}" (1), |
| 946 | // \\ [arg2] "{rsi}" (@ptrToInt("hello\n")), |
| 947 | // \\ [arg3] "{rdx}" (6) |
| 948 | // \\ : "rcx", "r11", "memory" |
| 949 | // \\ ); |
| 950 | // \\ return; |
| 951 | // \\} |
| 952 | // \\ |
| 953 | // \\fn exit() noreturn { |
| 954 | // \\ asm volatile ("syscall" |
| 955 | // \\ : |
| 956 | // \\ : [number] "{rax}" (231), |
| 957 | // \\ [arg1] "{rdi}" (0) |
| 958 | // \\ : "rcx", "r11", "memory" |
| 959 | // \\ ); |
| 960 | // \\ unreachable; |
| 961 | // \\} |
| 962 | //, |
| 963 | // "hello\nhello\nhello\nhello\nhello\n", |
| 964 | //); |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | | { |
| 968 | | var case = ctx.exe("basic import", linux_x64); |
| 969 | | case.addCompareOutput( |
| 970 | | \\export fn _start() noreturn { |
| 971 | | \\ @import("print.zig").print(); |
| 972 | | \\ exit(); |
| 973 | | \\} |
| 974 | | \\ |
| 975 | | \\fn exit() noreturn { |
| 976 | | \\ asm volatile ("syscall" |
| 977 | | \\ : |
| 978 | | \\ : [number] "{rax}" (231), |
| 979 | | \\ [arg1] "{rdi}" (@as(usize, 0)) |
| 980 | | \\ : "rcx", "r11", "memory" |
| 981 | | \\ ); |
| 982 | | \\ unreachable; |
| 983 | | \\} |
| 984 | | , |
| 985 | | "Hello, World!\n", |
| 986 | | ); |
| 987 | | try case.files.append(.{ |
| 988 | | .src = |
| 989 | | \\pub fn print() void { |
| 990 | | \\ asm volatile ("syscall" |
| 991 | | \\ : |
| 992 | | \\ : [number] "{rax}" (@as(usize, 1)), |
| 993 | | \\ [arg1] "{rdi}" (@as(usize, 1)), |
| 994 | | \\ [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")), |
| 995 | | \\ [arg3] "{rdx}" (@as(usize, 14)) |
| 996 | | \\ : "rcx", "r11", "memory" |
| 997 | | \\ ); |
| 998 | | \\ return; |
| 999 | | \\} |
| 1000 | | , |
| 1001 | | .path = "print.zig", |
| 1002 | | }); |
| 1003 | | } |
| 967 | //{ |
| 968 | // var case = ctx.exe("basic import", linux_x64); |
| 969 | // case.addCompareOutput( |
| 970 | // \\export fn _start() noreturn { |
| 971 | // \\ @import("print.zig").print(); |
| 972 | // \\ exit(); |
| 973 | // \\} |
| 974 | // \\ |
| 975 | // \\fn exit() noreturn { |
| 976 | // \\ asm volatile ("syscall" |
| 977 | // \\ : |
| 978 | // \\ : [number] "{rax}" (231), |
| 979 | // \\ [arg1] "{rdi}" (@as(usize, 0)) |
| 980 | // \\ : "rcx", "r11", "memory" |
| 981 | // \\ ); |
| 982 | // \\ unreachable; |
| 983 | // \\} |
| 984 | // , |
| 985 | // "Hello, World!\n", |
| 986 | // ); |
| 987 | // try case.files.append(.{ |
| 988 | // .src = |
| 989 | // \\pub fn print() void { |
| 990 | // \\ asm volatile ("syscall" |
| 991 | // \\ : |
| 992 | // \\ : [number] "{rax}" (@as(usize, 1)), |
| 993 | // \\ [arg1] "{rdi}" (@as(usize, 1)), |
| 994 | // \\ [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")), |
| 995 | // \\ [arg3] "{rdx}" (@as(usize, 14)) |
| 996 | // \\ : "rcx", "r11", "memory" |
| 997 | // \\ ); |
| 998 | // \\ return; |
| 999 | // \\} |
| 1000 | // , |
| 1001 | // .path = "print.zig", |
| 1002 | // }); |
| 1003 | //} |
| 1004 | 1004 | |
| 1005 | 1005 | ctx.compileError("function redefinition", linux_x64, |
| 1006 | 1006 | \\fn entry() void {} |
| ... | ... | @@ -1014,174 +1014,174 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1014 | 1014 | \\} |
| 1015 | 1015 | , &[_][]const u8{":2:3: error: this is an error"}); |
| 1016 | 1016 | |
| 1017 | | { |
| 1018 | | var case = ctx.obj("variable shadowing", linux_x64); |
| 1019 | | case.addError( |
| 1020 | | \\export fn _start() noreturn { |
| 1021 | | \\ var i: u32 = 10; |
| 1022 | | \\ var i: u32 = 10; |
| 1023 | | \\ unreachable; |
| 1024 | | \\} |
| 1025 | | , &[_][]const u8{ |
| 1026 | | ":3:9: error: redefinition of 'i'", |
| 1027 | | ":2:9: note: previous definition is here", |
| 1028 | | }); |
| 1029 | | case.addError( |
| 1030 | | \\var testing: i64 = 10; |
| 1031 | | \\export fn _start() noreturn { |
| 1032 | | \\ var testing: i64 = 20; |
| 1033 | | \\ unreachable; |
| 1034 | | \\} |
| 1035 | | , &[_][]const u8{":3:9: error: redefinition of 'testing'"}); |
| 1036 | | } |
| 1017 | //{ |
| 1018 | // var case = ctx.obj("variable shadowing", linux_x64); |
| 1019 | // case.addError( |
| 1020 | // \\export fn _start() noreturn { |
| 1021 | // \\ var i: u32 = 10; |
| 1022 | // \\ var i: u32 = 10; |
| 1023 | // \\ unreachable; |
| 1024 | // \\} |
| 1025 | // , &[_][]const u8{ |
| 1026 | // ":3:9: error: redefinition of 'i'", |
| 1027 | // ":2:9: note: previous definition is here", |
| 1028 | // }); |
| 1029 | // case.addError( |
| 1030 | // \\var testing: i64 = 10; |
| 1031 | // \\export fn _start() noreturn { |
| 1032 | // \\ var testing: i64 = 20; |
| 1033 | // \\ unreachable; |
| 1034 | // \\} |
| 1035 | // , &[_][]const u8{":3:9: error: redefinition of 'testing'"}); |
| 1036 | //} |
| 1037 | 1037 | |
| 1038 | | { |
| 1039 | | // TODO make the test harness support checking the compile log output too |
| 1040 | | var case = ctx.obj("@compileLog", linux_x64); |
| 1041 | | // The other compile error prevents emission of a "found compile log" statement. |
| 1042 | | case.addError( |
| 1043 | | \\export fn _start() noreturn { |
| 1044 | | \\ const b = true; |
| 1045 | | \\ var f: u32 = 1; |
| 1046 | | \\ @compileLog(b, 20, f, x); |
| 1047 | | \\ @compileLog(1000); |
| 1048 | | \\ var bruh: usize = true; |
| 1049 | | \\ unreachable; |
| 1050 | | \\} |
| 1051 | | \\export fn other() void { |
| 1052 | | \\ @compileLog(1234); |
| 1053 | | \\} |
| 1054 | | \\fn x() void {} |
| 1055 | | , &[_][]const u8{ |
| 1056 | | ":6:23: error: expected usize, found bool", |
| 1057 | | }); |
| 1038 | //{ |
| 1039 | // // TODO make the test harness support checking the compile log output too |
| 1040 | // var case = ctx.obj("@compileLog", linux_x64); |
| 1041 | // // The other compile error prevents emission of a "found compile log" statement. |
| 1042 | // case.addError( |
| 1043 | // \\export fn _start() noreturn { |
| 1044 | // \\ const b = true; |
| 1045 | // \\ var f: u32 = 1; |
| 1046 | // \\ @compileLog(b, 20, f, x); |
| 1047 | // \\ @compileLog(1000); |
| 1048 | // \\ var bruh: usize = true; |
| 1049 | // \\ unreachable; |
| 1050 | // \\} |
| 1051 | // \\export fn other() void { |
| 1052 | // \\ @compileLog(1234); |
| 1053 | // \\} |
| 1054 | // \\fn x() void {} |
| 1055 | // , &[_][]const u8{ |
| 1056 | // ":6:23: error: expected usize, found bool", |
| 1057 | // }); |
| 1058 | 1058 | |
| 1059 | | // Now only compile log statements remain. One per Decl. |
| 1060 | | case.addError( |
| 1061 | | \\export fn _start() noreturn { |
| 1062 | | \\ const b = true; |
| 1063 | | \\ var f: u32 = 1; |
| 1064 | | \\ @compileLog(b, 20, f, x); |
| 1065 | | \\ @compileLog(1000); |
| 1066 | | \\ unreachable; |
| 1067 | | \\} |
| 1068 | | \\export fn other() void { |
| 1069 | | \\ @compileLog(1234); |
| 1070 | | \\} |
| 1071 | | \\fn x() void {} |
| 1072 | | , &[_][]const u8{ |
| 1073 | | ":11:8: error: found compile log statement", |
| 1074 | | ":4:5: note: also here", |
| 1075 | | }); |
| 1076 | | } |
| 1059 | // // Now only compile log statements remain. One per Decl. |
| 1060 | // case.addError( |
| 1061 | // \\export fn _start() noreturn { |
| 1062 | // \\ const b = true; |
| 1063 | // \\ var f: u32 = 1; |
| 1064 | // \\ @compileLog(b, 20, f, x); |
| 1065 | // \\ @compileLog(1000); |
| 1066 | // \\ unreachable; |
| 1067 | // \\} |
| 1068 | // \\export fn other() void { |
| 1069 | // \\ @compileLog(1234); |
| 1070 | // \\} |
| 1071 | // \\fn x() void {} |
| 1072 | // , &[_][]const u8{ |
| 1073 | // ":11:8: error: found compile log statement", |
| 1074 | // ":4:5: note: also here", |
| 1075 | // }); |
| 1076 | //} |
| 1077 | 1077 | |
| 1078 | | { |
| 1079 | | var case = ctx.obj("extern variable has no type", linux_x64); |
| 1080 | | case.addError( |
| 1081 | | \\comptime { |
| 1082 | | \\ _ = foo; |
| 1083 | | \\} |
| 1084 | | \\extern var foo: i32; |
| 1085 | | , &[_][]const u8{":2:9: error: unable to resolve comptime value"}); |
| 1086 | | case.addError( |
| 1087 | | \\export fn entry() void { |
| 1088 | | \\ _ = foo; |
| 1089 | | \\} |
| 1090 | | \\extern var foo; |
| 1091 | | , &[_][]const u8{":4:8: error: unable to infer variable type"}); |
| 1092 | | } |
| 1078 | //{ |
| 1079 | // var case = ctx.obj("extern variable has no type", linux_x64); |
| 1080 | // case.addError( |
| 1081 | // \\comptime { |
| 1082 | // \\ _ = foo; |
| 1083 | // \\} |
| 1084 | // \\extern var foo: i32; |
| 1085 | // , &[_][]const u8{":2:9: error: unable to resolve comptime value"}); |
| 1086 | // case.addError( |
| 1087 | // \\export fn entry() void { |
| 1088 | // \\ _ = foo; |
| 1089 | // \\} |
| 1090 | // \\extern var foo; |
| 1091 | // , &[_][]const u8{":4:8: error: unable to infer variable type"}); |
| 1092 | //} |
| 1093 | 1093 | |
| 1094 | | { |
| 1095 | | var case = ctx.exe("break/continue", linux_x64); |
| 1094 | //{ |
| 1095 | // var case = ctx.exe("break/continue", linux_x64); |
| 1096 | 1096 | |
| 1097 | | // Break out of loop |
| 1098 | | case.addCompareOutput( |
| 1099 | | \\export fn _start() noreturn { |
| 1100 | | \\ while (true) { |
| 1101 | | \\ break; |
| 1102 | | \\ } |
| 1103 | | \\ |
| 1104 | | \\ exit(); |
| 1105 | | \\} |
| 1106 | | \\ |
| 1107 | | \\fn exit() noreturn { |
| 1108 | | \\ asm volatile ("syscall" |
| 1109 | | \\ : |
| 1110 | | \\ : [number] "{rax}" (231), |
| 1111 | | \\ [arg1] "{rdi}" (0) |
| 1112 | | \\ : "rcx", "r11", "memory" |
| 1113 | | \\ ); |
| 1114 | | \\ unreachable; |
| 1115 | | \\} |
| 1116 | | , |
| 1117 | | "", |
| 1118 | | ); |
| 1119 | | case.addCompareOutput( |
| 1120 | | \\export fn _start() noreturn { |
| 1121 | | \\ foo: while (true) { |
| 1122 | | \\ break :foo; |
| 1123 | | \\ } |
| 1124 | | \\ |
| 1125 | | \\ exit(); |
| 1126 | | \\} |
| 1127 | | \\ |
| 1128 | | \\fn exit() noreturn { |
| 1129 | | \\ asm volatile ("syscall" |
| 1130 | | \\ : |
| 1131 | | \\ : [number] "{rax}" (231), |
| 1132 | | \\ [arg1] "{rdi}" (0) |
| 1133 | | \\ : "rcx", "r11", "memory" |
| 1134 | | \\ ); |
| 1135 | | \\ unreachable; |
| 1136 | | \\} |
| 1137 | | , |
| 1138 | | "", |
| 1139 | | ); |
| 1097 | // // Break out of loop |
| 1098 | // case.addCompareOutput( |
| 1099 | // \\export fn _start() noreturn { |
| 1100 | // \\ while (true) { |
| 1101 | // \\ break; |
| 1102 | // \\ } |
| 1103 | // \\ |
| 1104 | // \\ exit(); |
| 1105 | // \\} |
| 1106 | // \\ |
| 1107 | // \\fn exit() noreturn { |
| 1108 | // \\ asm volatile ("syscall" |
| 1109 | // \\ : |
| 1110 | // \\ : [number] "{rax}" (231), |
| 1111 | // \\ [arg1] "{rdi}" (0) |
| 1112 | // \\ : "rcx", "r11", "memory" |
| 1113 | // \\ ); |
| 1114 | // \\ unreachable; |
| 1115 | // \\} |
| 1116 | // , |
| 1117 | // "", |
| 1118 | // ); |
| 1119 | // case.addCompareOutput( |
| 1120 | // \\export fn _start() noreturn { |
| 1121 | // \\ foo: while (true) { |
| 1122 | // \\ break :foo; |
| 1123 | // \\ } |
| 1124 | // \\ |
| 1125 | // \\ exit(); |
| 1126 | // \\} |
| 1127 | // \\ |
| 1128 | // \\fn exit() noreturn { |
| 1129 | // \\ asm volatile ("syscall" |
| 1130 | // \\ : |
| 1131 | // \\ : [number] "{rax}" (231), |
| 1132 | // \\ [arg1] "{rdi}" (0) |
| 1133 | // \\ : "rcx", "r11", "memory" |
| 1134 | // \\ ); |
| 1135 | // \\ unreachable; |
| 1136 | // \\} |
| 1137 | // , |
| 1138 | // "", |
| 1139 | // ); |
| 1140 | 1140 | |
| 1141 | | // Continue in loop |
| 1142 | | case.addCompareOutput( |
| 1143 | | \\export fn _start() noreturn { |
| 1144 | | \\ var i: u64 = 0; |
| 1145 | | \\ while (true) : (i+=1) { |
| 1146 | | \\ if (i == 4) exit(); |
| 1147 | | \\ continue; |
| 1148 | | \\ } |
| 1149 | | \\} |
| 1150 | | \\ |
| 1151 | | \\fn exit() noreturn { |
| 1152 | | \\ asm volatile ("syscall" |
| 1153 | | \\ : |
| 1154 | | \\ : [number] "{rax}" (231), |
| 1155 | | \\ [arg1] "{rdi}" (0) |
| 1156 | | \\ : "rcx", "r11", "memory" |
| 1157 | | \\ ); |
| 1158 | | \\ unreachable; |
| 1159 | | \\} |
| 1160 | | , |
| 1161 | | "", |
| 1162 | | ); |
| 1163 | | case.addCompareOutput( |
| 1164 | | \\export fn _start() noreturn { |
| 1165 | | \\ var i: u64 = 0; |
| 1166 | | \\ foo: while (true) : (i+=1) { |
| 1167 | | \\ if (i == 4) exit(); |
| 1168 | | \\ continue :foo; |
| 1169 | | \\ } |
| 1170 | | \\} |
| 1171 | | \\ |
| 1172 | | \\fn exit() noreturn { |
| 1173 | | \\ asm volatile ("syscall" |
| 1174 | | \\ : |
| 1175 | | \\ : [number] "{rax}" (231), |
| 1176 | | \\ [arg1] "{rdi}" (0) |
| 1177 | | \\ : "rcx", "r11", "memory" |
| 1178 | | \\ ); |
| 1179 | | \\ unreachable; |
| 1180 | | \\} |
| 1181 | | , |
| 1182 | | "", |
| 1183 | | ); |
| 1184 | | } |
| 1141 | // // Continue in loop |
| 1142 | // case.addCompareOutput( |
| 1143 | // \\export fn _start() noreturn { |
| 1144 | // \\ var i: u64 = 0; |
| 1145 | // \\ while (true) : (i+=1) { |
| 1146 | // \\ if (i == 4) exit(); |
| 1147 | // \\ continue; |
| 1148 | // \\ } |
| 1149 | // \\} |
| 1150 | // \\ |
| 1151 | // \\fn exit() noreturn { |
| 1152 | // \\ asm volatile ("syscall" |
| 1153 | // \\ : |
| 1154 | // \\ : [number] "{rax}" (231), |
| 1155 | // \\ [arg1] "{rdi}" (0) |
| 1156 | // \\ : "rcx", "r11", "memory" |
| 1157 | // \\ ); |
| 1158 | // \\ unreachable; |
| 1159 | // \\} |
| 1160 | // , |
| 1161 | // "", |
| 1162 | // ); |
| 1163 | // case.addCompareOutput( |
| 1164 | // \\export fn _start() noreturn { |
| 1165 | // \\ var i: u64 = 0; |
| 1166 | // \\ foo: while (true) : (i+=1) { |
| 1167 | // \\ if (i == 4) exit(); |
| 1168 | // \\ continue :foo; |
| 1169 | // \\ } |
| 1170 | // \\} |
| 1171 | // \\ |
| 1172 | // \\fn exit() noreturn { |
| 1173 | // \\ asm volatile ("syscall" |
| 1174 | // \\ : |
| 1175 | // \\ : [number] "{rax}" (231), |
| 1176 | // \\ [arg1] "{rdi}" (0) |
| 1177 | // \\ : "rcx", "r11", "memory" |
| 1178 | // \\ ); |
| 1179 | // \\ unreachable; |
| 1180 | // \\} |
| 1181 | // , |
| 1182 | // "", |
| 1183 | // ); |
| 1184 | //} |
| 1185 | 1185 | |
| 1186 | 1186 | { |
| 1187 | 1187 | var case = ctx.exe("unused labels", linux_x64); |
| ... | ... | @@ -1195,11 +1195,11 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1195 | 1195 | \\ foo: while (true) {} |
| 1196 | 1196 | \\} |
| 1197 | 1197 | , &[_][]const u8{":2:5: error: unused while loop label"}); |
| 1198 | | case.addError( |
| 1199 | | \\comptime { |
| 1200 | | \\ foo: for ("foo") |_| {} |
| 1201 | | \\} |
| 1202 | | , &[_][]const u8{":2:5: error: unused for loop label"}); |
| 1198 | //case.addError( |
| 1199 | // \\comptime { |
| 1200 | // \\ foo: for ("foo") |_| {} |
| 1201 | // \\} |
| 1202 | //, &[_][]const u8{":2:5: error: unused for loop label"}); |
| 1203 | 1203 | case.addError( |
| 1204 | 1204 | \\comptime { |
| 1205 | 1205 | \\ blk: {blk: {}} |
| ... | ... | @@ -1210,14 +1210,14 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1210 | 1210 | }); |
| 1211 | 1211 | } |
| 1212 | 1212 | |
| 1213 | | { |
| 1214 | | var case = ctx.exe("bad inferred variable type", linux_x64); |
| 1215 | | case.addError( |
| 1216 | | \\export fn foo() void { |
| 1217 | | \\ var x = null; |
| 1218 | | \\} |
| 1219 | | , &[_][]const u8{":2:9: error: variable of type '@Type(.Null)' must be const or comptime"}); |
| 1220 | | } |
| 1213 | //{ |
| 1214 | // var case = ctx.exe("bad inferred variable type", linux_x64); |
| 1215 | // case.addError( |
| 1216 | // \\export fn foo() void { |
| 1217 | // \\ var x = null; |
| 1218 | // \\} |
| 1219 | // , &[_][]const u8{":2:9: error: variable of type '@Type(.Null)' must be const or comptime"}); |
| 1220 | //} |
| 1221 | 1221 | |
| 1222 | 1222 | { |
| 1223 | 1223 | var case = ctx.exe("compile error in inline fn call fixed", linux_x64); |
| ... | ... | @@ -1294,10 +1294,9 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1294 | 1294 | , |
| 1295 | 1295 | "", |
| 1296 | 1296 | ); |
| 1297 | | // TODO this should be :8:21 not :8:19. we need to improve source locations |
| 1298 | | // to be relative to the containing Decl so that they can survive when the byte |
| 1299 | | // offset of a previous Decl changes. Here the change from 7 to 999 introduces |
| 1300 | | // +2 to the byte offset and makes the error location wrong by 2 bytes. |
| 1297 | // This additionally tests that the compile error reports the correct source location. |
| 1298 | // Without storing source locations relative to the owner decl, the compile error |
| 1299 | // here would be off by 2 bytes (from the "7" -> "999"). |
| 1301 | 1300 | case.addError( |
| 1302 | 1301 | \\export fn _start() noreturn { |
| 1303 | 1302 | \\ const y = fibonacci(999); |
| ... | ... | @@ -1318,55 +1317,55 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1318 | 1317 | \\ ); |
| 1319 | 1318 | \\ unreachable; |
| 1320 | 1319 | \\} |
| 1321 | | , &[_][]const u8{":8:19: error: evaluation exceeded 1000 backwards branches"}); |
| 1322 | | } |
| 1323 | | { |
| 1324 | | var case = ctx.exe("orelse at comptime", linux_x64); |
| 1325 | | case.addCompareOutput( |
| 1326 | | \\export fn _start() noreturn { |
| 1327 | | \\ const i: ?u64 = 0; |
| 1328 | | \\ const orelsed = i orelse 5; |
| 1329 | | \\ assert(orelsed == 0); |
| 1330 | | \\ exit(); |
| 1331 | | \\} |
| 1332 | | \\fn assert(b: bool) void { |
| 1333 | | \\ if (!b) unreachable; |
| 1334 | | \\} |
| 1335 | | \\fn exit() noreturn { |
| 1336 | | \\ asm volatile ("syscall" |
| 1337 | | \\ : |
| 1338 | | \\ : [number] "{rax}" (231), |
| 1339 | | \\ [arg1] "{rdi}" (0) |
| 1340 | | \\ : "rcx", "r11", "memory" |
| 1341 | | \\ ); |
| 1342 | | \\ unreachable; |
| 1343 | | \\} |
| 1344 | | , |
| 1345 | | "", |
| 1346 | | ); |
| 1347 | | case.addCompareOutput( |
| 1348 | | \\export fn _start() noreturn { |
| 1349 | | \\ const i: ?u64 = null; |
| 1350 | | \\ const orelsed = i orelse 5; |
| 1351 | | \\ assert(orelsed == 5); |
| 1352 | | \\ exit(); |
| 1353 | | \\} |
| 1354 | | \\fn assert(b: bool) void { |
| 1355 | | \\ if (!b) unreachable; |
| 1356 | | \\} |
| 1357 | | \\fn exit() noreturn { |
| 1358 | | \\ asm volatile ("syscall" |
| 1359 | | \\ : |
| 1360 | | \\ : [number] "{rax}" (231), |
| 1361 | | \\ [arg1] "{rdi}" (0) |
| 1362 | | \\ : "rcx", "r11", "memory" |
| 1363 | | \\ ); |
| 1364 | | \\ unreachable; |
| 1365 | | \\} |
| 1366 | | , |
| 1367 | | "", |
| 1368 | | ); |
| 1320 | , &[_][]const u8{":8:21: error: evaluation exceeded 1000 backwards branches"}); |
| 1369 | 1321 | } |
| 1322 | //{ |
| 1323 | // var case = ctx.exe("orelse at comptime", linux_x64); |
| 1324 | // case.addCompareOutput( |
| 1325 | // \\export fn _start() noreturn { |
| 1326 | // \\ const i: ?u64 = 0; |
| 1327 | // \\ const orelsed = i orelse 5; |
| 1328 | // \\ assert(orelsed == 0); |
| 1329 | // \\ exit(); |
| 1330 | // \\} |
| 1331 | // \\fn assert(b: bool) void { |
| 1332 | // \\ if (!b) unreachable; |
| 1333 | // \\} |
| 1334 | // \\fn exit() noreturn { |
| 1335 | // \\ asm volatile ("syscall" |
| 1336 | // \\ : |
| 1337 | // \\ : [number] "{rax}" (231), |
| 1338 | // \\ [arg1] "{rdi}" (0) |
| 1339 | // \\ : "rcx", "r11", "memory" |
| 1340 | // \\ ); |
| 1341 | // \\ unreachable; |
| 1342 | // \\} |
| 1343 | // , |
| 1344 | // "", |
| 1345 | // ); |
| 1346 | // case.addCompareOutput( |
| 1347 | // \\export fn _start() noreturn { |
| 1348 | // \\ const i: ?u64 = null; |
| 1349 | // \\ const orelsed = i orelse 5; |
| 1350 | // \\ assert(orelsed == 5); |
| 1351 | // \\ exit(); |
| 1352 | // \\} |
| 1353 | // \\fn assert(b: bool) void { |
| 1354 | // \\ if (!b) unreachable; |
| 1355 | // \\} |
| 1356 | // \\fn exit() noreturn { |
| 1357 | // \\ asm volatile ("syscall" |
| 1358 | // \\ : |
| 1359 | // \\ : [number] "{rax}" (231), |
| 1360 | // \\ [arg1] "{rdi}" (0) |
| 1361 | // \\ : "rcx", "r11", "memory" |
| 1362 | // \\ ); |
| 1363 | // \\ unreachable; |
| 1364 | // \\} |
| 1365 | // , |
| 1366 | // "", |
| 1367 | // ); |
| 1368 | //} |
| 1370 | 1369 | |
| 1371 | 1370 | { |
| 1372 | 1371 | var case = ctx.exe("only 1 function and it gets updated", linux_x64); |
| ... | ... | @@ -1418,144 +1417,144 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1418 | 1417 | "", |
| 1419 | 1418 | ); |
| 1420 | 1419 | } |
| 1421 | | { |
| 1422 | | var case = ctx.exe("catch at comptime", linux_x64); |
| 1423 | | case.addCompareOutput( |
| 1424 | | \\export fn _start() noreturn { |
| 1425 | | \\ const i: anyerror!u64 = 0; |
| 1426 | | \\ const caught = i catch 5; |
| 1427 | | \\ assert(caught == 0); |
| 1428 | | \\ exit(); |
| 1429 | | \\} |
| 1430 | | \\fn assert(b: bool) void { |
| 1431 | | \\ if (!b) unreachable; |
| 1432 | | \\} |
| 1433 | | \\fn exit() noreturn { |
| 1434 | | \\ asm volatile ("syscall" |
| 1435 | | \\ : |
| 1436 | | \\ : [number] "{rax}" (231), |
| 1437 | | \\ [arg1] "{rdi}" (0) |
| 1438 | | \\ : "rcx", "r11", "memory" |
| 1439 | | \\ ); |
| 1440 | | \\ unreachable; |
| 1441 | | \\} |
| 1442 | | , |
| 1443 | | "", |
| 1444 | | ); |
| 1445 | | case.addCompareOutput( |
| 1446 | | \\export fn _start() noreturn { |
| 1447 | | \\ const i: anyerror!u64 = error.B; |
| 1448 | | \\ const caught = i catch 5; |
| 1449 | | \\ assert(caught == 5); |
| 1450 | | \\ exit(); |
| 1451 | | \\} |
| 1452 | | \\fn assert(b: bool) void { |
| 1453 | | \\ if (!b) unreachable; |
| 1454 | | \\} |
| 1455 | | \\fn exit() noreturn { |
| 1456 | | \\ asm volatile ("syscall" |
| 1457 | | \\ : |
| 1458 | | \\ : [number] "{rax}" (231), |
| 1459 | | \\ [arg1] "{rdi}" (0) |
| 1460 | | \\ : "rcx", "r11", "memory" |
| 1461 | | \\ ); |
| 1462 | | \\ unreachable; |
| 1463 | | \\} |
| 1464 | | , |
| 1465 | | "", |
| 1466 | | ); |
| 1467 | | case.addCompareOutput( |
| 1468 | | \\export fn _start() noreturn { |
| 1469 | | \\ const a: anyerror!comptime_int = 42; |
| 1470 | | \\ const b: *const comptime_int = &(a catch unreachable); |
| 1471 | | \\ assert(b.* == 42); |
| 1472 | | \\ |
| 1473 | | \\ exit(); |
| 1474 | | \\} |
| 1475 | | \\fn assert(b: bool) void { |
| 1476 | | \\ if (!b) unreachable; // assertion failure |
| 1477 | | \\} |
| 1478 | | \\fn exit() noreturn { |
| 1479 | | \\ asm volatile ("syscall" |
| 1480 | | \\ : |
| 1481 | | \\ : [number] "{rax}" (231), |
| 1482 | | \\ [arg1] "{rdi}" (0) |
| 1483 | | \\ : "rcx", "r11", "memory" |
| 1484 | | \\ ); |
| 1485 | | \\ unreachable; |
| 1486 | | \\} |
| 1487 | | , ""); |
| 1488 | | case.addCompareOutput( |
| 1489 | | \\export fn _start() noreturn { |
| 1490 | | \\const a: anyerror!u32 = error.B; |
| 1491 | | \\_ = &(a catch |err| assert(err == error.B)); |
| 1492 | | \\exit(); |
| 1493 | | \\} |
| 1494 | | \\fn assert(b: bool) void { |
| 1495 | | \\ if (!b) unreachable; |
| 1496 | | \\} |
| 1497 | | \\fn exit() noreturn { |
| 1498 | | \\ asm volatile ("syscall" |
| 1499 | | \\ : |
| 1500 | | \\ : [number] "{rax}" (231), |
| 1501 | | \\ [arg1] "{rdi}" (0) |
| 1502 | | \\ : "rcx", "r11", "memory" |
| 1503 | | \\ ); |
| 1504 | | \\ unreachable; |
| 1505 | | \\} |
| 1506 | | , ""); |
| 1507 | | case.addCompareOutput( |
| 1508 | | \\export fn _start() noreturn { |
| 1509 | | \\ const a: anyerror!u32 = error.Bar; |
| 1510 | | \\ a catch |err| assert(err == error.Bar); |
| 1511 | | \\ |
| 1512 | | \\ exit(); |
| 1513 | | \\} |
| 1514 | | \\fn assert(b: bool) void { |
| 1515 | | \\ if (!b) unreachable; |
| 1516 | | \\} |
| 1517 | | \\fn exit() noreturn { |
| 1518 | | \\ asm volatile ("syscall" |
| 1519 | | \\ : |
| 1520 | | \\ : [number] "{rax}" (231), |
| 1521 | | \\ [arg1] "{rdi}" (0) |
| 1522 | | \\ : "rcx", "r11", "memory" |
| 1523 | | \\ ); |
| 1524 | | \\ unreachable; |
| 1525 | | \\} |
| 1526 | | , ""); |
| 1527 | | } |
| 1528 | | { |
| 1529 | | var case = ctx.exe("merge error sets", linux_x64); |
| 1420 | //{ |
| 1421 | // var case = ctx.exe("catch at comptime", linux_x64); |
| 1422 | // case.addCompareOutput( |
| 1423 | // \\export fn _start() noreturn { |
| 1424 | // \\ const i: anyerror!u64 = 0; |
| 1425 | // \\ const caught = i catch 5; |
| 1426 | // \\ assert(caught == 0); |
| 1427 | // \\ exit(); |
| 1428 | // \\} |
| 1429 | // \\fn assert(b: bool) void { |
| 1430 | // \\ if (!b) unreachable; |
| 1431 | // \\} |
| 1432 | // \\fn exit() noreturn { |
| 1433 | // \\ asm volatile ("syscall" |
| 1434 | // \\ : |
| 1435 | // \\ : [number] "{rax}" (231), |
| 1436 | // \\ [arg1] "{rdi}" (0) |
| 1437 | // \\ : "rcx", "r11", "memory" |
| 1438 | // \\ ); |
| 1439 | // \\ unreachable; |
| 1440 | // \\} |
| 1441 | // , |
| 1442 | // "", |
| 1443 | // ); |
| 1444 | // case.addCompareOutput( |
| 1445 | // \\export fn _start() noreturn { |
| 1446 | // \\ const i: anyerror!u64 = error.B; |
| 1447 | // \\ const caught = i catch 5; |
| 1448 | // \\ assert(caught == 5); |
| 1449 | // \\ exit(); |
| 1450 | // \\} |
| 1451 | // \\fn assert(b: bool) void { |
| 1452 | // \\ if (!b) unreachable; |
| 1453 | // \\} |
| 1454 | // \\fn exit() noreturn { |
| 1455 | // \\ asm volatile ("syscall" |
| 1456 | // \\ : |
| 1457 | // \\ : [number] "{rax}" (231), |
| 1458 | // \\ [arg1] "{rdi}" (0) |
| 1459 | // \\ : "rcx", "r11", "memory" |
| 1460 | // \\ ); |
| 1461 | // \\ unreachable; |
| 1462 | // \\} |
| 1463 | // , |
| 1464 | // "", |
| 1465 | // ); |
| 1466 | // case.addCompareOutput( |
| 1467 | // \\export fn _start() noreturn { |
| 1468 | // \\ const a: anyerror!comptime_int = 42; |
| 1469 | // \\ const b: *const comptime_int = &(a catch unreachable); |
| 1470 | // \\ assert(b.* == 42); |
| 1471 | // \\ |
| 1472 | // \\ exit(); |
| 1473 | // \\} |
| 1474 | // \\fn assert(b: bool) void { |
| 1475 | // \\ if (!b) unreachable; // assertion failure |
| 1476 | // \\} |
| 1477 | // \\fn exit() noreturn { |
| 1478 | // \\ asm volatile ("syscall" |
| 1479 | // \\ : |
| 1480 | // \\ : [number] "{rax}" (231), |
| 1481 | // \\ [arg1] "{rdi}" (0) |
| 1482 | // \\ : "rcx", "r11", "memory" |
| 1483 | // \\ ); |
| 1484 | // \\ unreachable; |
| 1485 | // \\} |
| 1486 | // , ""); |
| 1487 | // case.addCompareOutput( |
| 1488 | // \\export fn _start() noreturn { |
| 1489 | // \\const a: anyerror!u32 = error.B; |
| 1490 | // \\_ = &(a catch |err| assert(err == error.B)); |
| 1491 | // \\exit(); |
| 1492 | // \\} |
| 1493 | // \\fn assert(b: bool) void { |
| 1494 | // \\ if (!b) unreachable; |
| 1495 | // \\} |
| 1496 | // \\fn exit() noreturn { |
| 1497 | // \\ asm volatile ("syscall" |
| 1498 | // \\ : |
| 1499 | // \\ : [number] "{rax}" (231), |
| 1500 | // \\ [arg1] "{rdi}" (0) |
| 1501 | // \\ : "rcx", "r11", "memory" |
| 1502 | // \\ ); |
| 1503 | // \\ unreachable; |
| 1504 | // \\} |
| 1505 | // , ""); |
| 1506 | // case.addCompareOutput( |
| 1507 | // \\export fn _start() noreturn { |
| 1508 | // \\ const a: anyerror!u32 = error.Bar; |
| 1509 | // \\ a catch |err| assert(err == error.Bar); |
| 1510 | // \\ |
| 1511 | // \\ exit(); |
| 1512 | // \\} |
| 1513 | // \\fn assert(b: bool) void { |
| 1514 | // \\ if (!b) unreachable; |
| 1515 | // \\} |
| 1516 | // \\fn exit() noreturn { |
| 1517 | // \\ asm volatile ("syscall" |
| 1518 | // \\ : |
| 1519 | // \\ : [number] "{rax}" (231), |
| 1520 | // \\ [arg1] "{rdi}" (0) |
| 1521 | // \\ : "rcx", "r11", "memory" |
| 1522 | // \\ ); |
| 1523 | // \\ unreachable; |
| 1524 | // \\} |
| 1525 | // , ""); |
| 1526 | //} |
| 1527 | //{ |
| 1528 | // var case = ctx.exe("merge error sets", linux_x64); |
| 1530 | 1529 | |
| 1531 | | case.addCompareOutput( |
| 1532 | | \\export fn _start() noreturn { |
| 1533 | | \\ const E = error{ A, B, D } || error { A, B, C }; |
| 1534 | | \\ const a = E.A; |
| 1535 | | \\ const b = E.B; |
| 1536 | | \\ const c = E.C; |
| 1537 | | \\ const d = E.D; |
| 1538 | | \\ const E2 = error { X, Y } || @TypeOf(error.Z); |
| 1539 | | \\ const x = E2.X; |
| 1540 | | \\ const y = E2.Y; |
| 1541 | | \\ const z = E2.Z; |
| 1542 | | \\ assert(anyerror || error { Z } == anyerror); |
| 1543 | | \\ exit(); |
| 1544 | | \\} |
| 1545 | | \\fn assert(b: bool) void { |
| 1546 | | \\ if (!b) unreachable; |
| 1547 | | \\} |
| 1548 | | \\fn exit() noreturn { |
| 1549 | | \\ asm volatile ("syscall" |
| 1550 | | \\ : |
| 1551 | | \\ : [number] "{rax}" (231), |
| 1552 | | \\ [arg1] "{rdi}" (0) |
| 1553 | | \\ : "rcx", "r11", "memory" |
| 1554 | | \\ ); |
| 1555 | | \\ unreachable; |
| 1556 | | \\} |
| 1557 | | , |
| 1558 | | "", |
| 1559 | | ); |
| 1560 | | } |
| 1530 | // case.addCompareOutput( |
| 1531 | // \\export fn _start() noreturn { |
| 1532 | // \\ const E = error{ A, B, D } || error { A, B, C }; |
| 1533 | // \\ const a = E.A; |
| 1534 | // \\ const b = E.B; |
| 1535 | // \\ const c = E.C; |
| 1536 | // \\ const d = E.D; |
| 1537 | // \\ const E2 = error { X, Y } || @TypeOf(error.Z); |
| 1538 | // \\ const x = E2.X; |
| 1539 | // \\ const y = E2.Y; |
| 1540 | // \\ const z = E2.Z; |
| 1541 | // \\ assert(anyerror || error { Z } == anyerror); |
| 1542 | // \\ exit(); |
| 1543 | // \\} |
| 1544 | // \\fn assert(b: bool) void { |
| 1545 | // \\ if (!b) unreachable; |
| 1546 | // \\} |
| 1547 | // \\fn exit() noreturn { |
| 1548 | // \\ asm volatile ("syscall" |
| 1549 | // \\ : |
| 1550 | // \\ : [number] "{rax}" (231), |
| 1551 | // \\ [arg1] "{rdi}" (0) |
| 1552 | // \\ : "rcx", "r11", "memory" |
| 1553 | // \\ ); |
| 1554 | // \\ unreachable; |
| 1555 | // \\} |
| 1556 | // , |
| 1557 | // "", |
| 1558 | // ); |
| 1559 | //} |
| 1561 | 1560 | } |