commit b3f9fe6d0439bcbb5c6baa77c0646c4da2e06dd7 (tree) parent 52fe2ebee8023944c6e701f32ab161e0c30aed5b Author: mlugg <mlugg@mlugg.co.uk> Date: Wed, 19 Apr 2023 14:17:48 +0100 Unify incremental test cases and disable many The self-hosted aarch64 backend is not currently functional due to the Liveness changes. A previous commit disabled aarch64 on the behavior tests; this commit disables it and arm for the test cases. Moreover, all incremental test cases have been unified into shared cross-platform cases, which can be gradually enabled as the backends improve. Diffstat:
170 files changed, 525 insertions(+), 1607 deletions(-)
diff --git a/test/cases/aarch64-linux/conditional_branches.0.zig b/test/cases/aarch64-linux/conditional_branches.0.zig @@ -1,26 +0,0 @@ -pub fn main() void { - foo(123); -} - -fn foo(x: u64) void { - if (x > 42) { - print(); - } -} - -fn print() void { - asm volatile ("svc #0" - : - : [number] "{x8}" (64), - [arg1] "{x0}" (1), - [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), - [arg3] "{x2}" ("Hello, World!\n".len), - : "memory", "cc" - ); -} - -// run -// target=aarch64-linux -// -// Hello, World! -// diff --git a/test/cases/aarch64-linux/conditional_branches.1.zig b/test/cases/aarch64-linux/conditional_branches.1.zig @@ -1,25 +0,0 @@ -pub fn main() void { - foo(true); -} - -fn foo(x: bool) void { - if (x) { - print(); - } -} - -fn print() void { - asm volatile ("svc #0" - : - : [number] "{x8}" (64), - [arg1] "{x0}" (1), - [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), - [arg3] "{x2}" ("Hello, World!\n".len), - : "memory", "cc" - ); -} - -// run -// -// Hello, World! -// diff --git a/test/cases/aarch64-linux/hello_world_with_updates.0.zig b/test/cases/aarch64-linux/hello_world_with_updates.0.zig @@ -1,31 +0,0 @@ -pub export fn _start() noreturn { - print(); - exit(0); -} - -fn print() void { - asm volatile ("svc #0" - : - : [number] "{x8}" (64), - [arg1] "{x0}" (1), - [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), - [arg3] "{x2}" ("Hello, World!\n".len), - : "memory", "cc" - ); -} - -fn exit(ret: usize) noreturn { - asm volatile ("svc #0" - : - : [number] "{x8}" (93), - [arg1] "{x0}" (ret), - : "memory", "cc" - ); - unreachable; -} - -// run -// target=aarch64-linux -// -// Hello, World! -// diff --git a/test/cases/aarch64-linux/hello_world_with_updates.1.zig b/test/cases/aarch64-linux/hello_world_with_updates.1.zig @@ -1,36 +0,0 @@ -pub export fn _start() noreturn { - print(); - print(); - print(); - print(); - exit(0); -} - -fn print() void { - asm volatile ("svc #0" - : - : [number] "{x8}" (64), - [arg1] "{x0}" (1), - [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), - [arg3] "{x2}" ("Hello, World!\n".len), - : "memory", "cc" - ); -} - -fn exit(ret: usize) noreturn { - asm volatile ("svc #0" - : - : [number] "{x8}" (93), - [arg1] "{x0}" (ret), - : "memory", "cc" - ); - unreachable; -} - -// run -// -// Hello, World! -// Hello, World! -// Hello, World! -// Hello, World! -// diff --git a/test/cases/aarch64-linux/hello_world_with_updates.2.zig b/test/cases/aarch64-linux/hello_world_with_updates.2.zig @@ -1,21 +0,0 @@ -pub fn main() void { - print(); - print(); -} - -fn print() void { - asm volatile ("svc #0" - : - : [number] "{x8}" (64), - [arg1] "{x0}" (1), - [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), - [arg3] "{x2}" ("Hello, World!\n".len), - : "memory", "cc" - ); -} - -// run -// -// Hello, World! -// Hello, World! -// diff --git a/test/cases/aarch64-macos/hello_world_with_updates.0.zig b/test/cases/aarch64-macos/hello_world_with_updates.0.zig @@ -1,5 +0,0 @@ -// error -// output_mode=Exe -// target=aarch64-macos -// -// :?:?: error: root struct of file 'tmp' has no member named 'main' diff --git a/test/cases/aarch64-macos/hello_world_with_updates.2.zig b/test/cases/aarch64-macos/hello_world_with_updates.2.zig @@ -1,19 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; -extern "c" fn exit(usize) noreturn; - -pub export fn main() noreturn { - print(); - - exit(0); -} - -fn print() void { - const msg = @ptrToInt("Hello, World!\n"); - const len = 14; - _ = write(1, msg, len); -} - -// run -// -// Hello, World! -// diff --git a/test/cases/aarch64-macos/hello_world_with_updates.3.zig b/test/cases/aarch64-macos/hello_world_with_updates.3.zig @@ -1,16 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - print(); -} - -fn print() void { - const msg = @ptrToInt("Hello, World!\n"); - const len = 14; - _ = write(1, msg, len); -} - -// run -// -// Hello, World! -// diff --git a/test/cases/aarch64-macos/hello_world_with_updates.4.zig b/test/cases/aarch64-macos/hello_world_with_updates.4.zig @@ -1,22 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - print(); - print(); - print(); - print(); -} - -fn print() void { - const msg = @ptrToInt("Hello, World!\n"); - const len = 14; - _ = write(1, msg, len); -} - -// run -// -// Hello, World! -// Hello, World! -// Hello, World! -// Hello, World! -// diff --git a/test/cases/aarch64-macos/hello_world_with_updates.5.zig b/test/cases/aarch64-macos/hello_world_with_updates.5.zig @@ -1,16 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - print(); -} - -fn print() void { - const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); - const len = 104; - _ = write(1, msg, len); -} - -// run -// -// What is up? This is a longer message that will force the data to be relocated in virtual address space. -// diff --git a/test/cases/aarch64-macos/hello_world_with_updates.6.zig b/test/cases/aarch64-macos/hello_world_with_updates.6.zig @@ -1,18 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - print(); - print(); -} - -fn print() void { - const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); - const len = 104; - _ = write(1, msg, len); -} - -// run -// -// What is up? This is a longer message that will force the data to be relocated in virtual address space. -// What is up? This is a longer message that will force the data to be relocated in virtual address space. -// diff --git a/test/cases/arithmetic_operations.0.zig b/test/cases/arithmetic_operations.0.zig @@ -0,0 +1,17 @@ +const std = @import("std"); + +pub fn main() void { + print(2, 4); + print(1, 7); +} + +fn print(a: u32, b: u32) void { + const str = "123456789"; + const len = a + b; + _ = std.os.write(1, str[0..len]) catch {}; +} + +// run +// target=x86_64-linux,x86_64-macos +// +// 12345612345678 diff --git a/test/cases/arithmetic_operations.1.zig b/test/cases/arithmetic_operations.1.zig @@ -0,0 +1,16 @@ +const std = @import("std"); + +pub fn main() void { + print(10, 5); + print(4, 3); +} + +fn print(a: u32, b: u32) void { + const str = "123456789"; + const len = a - b; + _ = std.os.write(1, str[0..len]) catch {}; +} + +// run +// +// 123451 diff --git a/test/cases/arithmetic_operations.2.zig b/test/cases/arithmetic_operations.2.zig @@ -0,0 +1,16 @@ +const std = @import("std"); + +pub fn main() void { + print(8, 9); + print(3, 7); +} + +fn print(a: u32, b: u32) void { + const str = "123456789"; + const len = a & b; + _ = std.os.write(1, str[0..len]) catch {}; +} + +// run +// +// 12345678123 diff --git a/test/cases/arithmetic_operations.3.zig b/test/cases/arithmetic_operations.3.zig @@ -0,0 +1,16 @@ +const std = @import("std"); + +pub fn main() void { + print(4, 2); + print(3, 7); +} + +fn print(a: u32, b: u32) void { + const str = "123456789"; + const len = a | b; + _ = std.os.write(1, str[0..len]) catch {}; +} + +// run +// +// 1234561234567 diff --git a/test/cases/arithmetic_operations.4.zig b/test/cases/arithmetic_operations.4.zig @@ -0,0 +1,16 @@ +const std = @import("std"); + +pub fn main() void { + print(42, 42); + print(3, 5); +} + +fn print(a: u32, b: u32) void { + const str = "123456789"; + const len = a ^ b; + _ = std.os.write(1, str[0..len]) catch {}; +} + +// run +// +// 123456 diff --git a/test/cases/arm-linux/arithmetic_operations.5.zig b/test/cases/arithmetic_operations.5.zig diff --git a/test/cases/arm-linux/arithmetic_operations.6.zig b/test/cases/arithmetic_operations.6.zig diff --git a/test/cases/arm-linux/arithmetic_operations.0.zig b/test/cases/arm-linux/arithmetic_operations.0.zig @@ -1,21 +0,0 @@ -pub fn main() void { - print(2, 4); - print(1, 7); -} - -fn print(a: u32, b: u32) void { - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg3] "{r2}" (a + b), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("123456789")), - : "memory" - ); - return; -} - -// run -// target=arm-linux -// -// 12345612345678 diff --git a/test/cases/arm-linux/arithmetic_operations.1.zig b/test/cases/arm-linux/arithmetic_operations.1.zig @@ -1,20 +0,0 @@ -pub fn main() void { - print(10, 5); - print(4, 3); -} - -fn print(a: u32, b: u32) void { - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg3] "{r2}" (a - b), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("123456789")), - : "memory" - ); - return; -} - -// run -// -// 123451 diff --git a/test/cases/arm-linux/arithmetic_operations.2.zig b/test/cases/arm-linux/arithmetic_operations.2.zig @@ -1,20 +0,0 @@ -pub fn main() void { - print(8, 9); - print(3, 7); -} - -fn print(a: u32, b: u32) void { - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg3] "{r2}" (a & b), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("123456789")), - : "memory" - ); - return; -} - -// run -// -// 12345678123 diff --git a/test/cases/arm-linux/arithmetic_operations.3.zig b/test/cases/arm-linux/arithmetic_operations.3.zig @@ -1,20 +0,0 @@ -pub fn main() void { - print(4, 2); - print(3, 7); -} - -fn print(a: u32, b: u32) void { - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg3] "{r2}" (a | b), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("123456789")), - : "memory" - ); - return; -} - -// run -// -// 1234561234567 diff --git a/test/cases/arm-linux/arithmetic_operations.4.zig b/test/cases/arm-linux/arithmetic_operations.4.zig @@ -1,20 +0,0 @@ -pub fn main() void { - print(42, 42); - print(3, 5); -} - -fn print(a: u32, b: u32) void { - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg3] "{r2}" (a ^ b), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("123456789")), - : "memory" - ); - return; -} - -// run -// -// 123456 diff --git a/test/cases/arm-linux/errors.0.zig b/test/cases/arm-linux/errors.0.zig @@ -1,21 +0,0 @@ -pub fn main() void { - foo() catch print(); -} - -fn foo() anyerror!void {} - -fn print() void { - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("Hello, World!\n")), - [arg3] "{r2}" ("Hello, World!\n".len), - : "memory" - ); - return; -} - -// run -// target=arm-linux -// diff --git a/test/cases/arm-linux/errors.1.zig b/test/cases/arm-linux/errors.1.zig @@ -1,24 +0,0 @@ -pub fn main() void { - foo() catch print(); -} - -fn foo() anyerror!void { - return error.Test; -} - -fn print() void { - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("Hello, World!\n")), - [arg3] "{r2}" ("Hello, World!\n".len), - : "memory" - ); - return; -} - -// run -// -// Hello, World! -// diff --git a/test/cases/arm-linux/function_pointers.zig b/test/cases/arm-linux/function_pointers.zig @@ -1,44 +0,0 @@ -const PrintFn = *const fn () void; - -pub fn main() void { - var printFn: PrintFn = stopSayingThat; - var i: u32 = 0; - while (i < 4) : (i += 1) printFn(); - - printFn = moveEveryZig; - printFn(); -} - -fn stopSayingThat() void { - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n")), - [arg3] "{r2}" ("Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n".len), - : "memory" - ); - return; -} - -fn moveEveryZig() void { - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("All your codebase are belong to us\n")), - [arg3] "{r2}" ("All your codebase are belong to us\n".len), - : "memory" - ); - return; -} - -// run -// target=arm-linux -// -// Hello, my name is Inigo Montoya; you killed my father, prepare to die. -// Hello, my name is Inigo Montoya; you killed my father, prepare to die. -// Hello, my name is Inigo Montoya; you killed my father, prepare to die. -// Hello, my name is Inigo Montoya; you killed my father, prepare to die. -// All your codebase are belong to us -// diff --git a/test/cases/arm-linux/hello_world_with_updates.0.zig b/test/cases/arm-linux/hello_world_with_updates.0.zig @@ -1,32 +0,0 @@ -pub export fn _start() noreturn { - print(); - exit(); -} - -fn print() void { - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("Hello, World!\n")), - [arg3] "{r2}" (14), - : "memory" - ); - return; -} - -fn exit() noreturn { - asm volatile ("svc #0" - : - : [number] "{r7}" (1), - [arg1] "{r0}" (0), - : "memory" - ); - unreachable; -} - -// run -// target=arm-linux -// -// Hello, World! -// diff --git a/test/cases/arm-linux/hello_world_with_updates.1.zig b/test/cases/arm-linux/hello_world_with_updates.1.zig @@ -1,37 +0,0 @@ -pub export fn _start() noreturn { - print(); - print(); - print(); - print(); - exit(); -} - -fn print() void { - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("Hello, World!\n")), - [arg3] "{r2}" (14), - : "memory" - ); - return; -} - -fn exit() noreturn { - asm volatile ("svc #0" - : - : [number] "{r7}" (1), - [arg1] "{r0}" (0), - : "memory" - ); - unreachable; -} - -// run -// -// Hello, World! -// Hello, World! -// Hello, World! -// Hello, World! -// diff --git a/test/cases/arm-linux/hello_world_with_updates.2.zig b/test/cases/arm-linux/hello_world_with_updates.2.zig @@ -1,22 +0,0 @@ -pub fn main() void { - print(); - print(); -} - -fn print() void { - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("Hello, World!\n")), - [arg3] "{r2}" (14), - : "memory" - ); - return; -} - -// run -// -// Hello, World! -// Hello, World! -// diff --git a/test/cases/arm-linux/parameters_and_return_values.0.zig b/test/cases/arm-linux/parameters_and_return_values.0.zig @@ -1,28 +0,0 @@ -pub fn main() void { - print(id(14)); -} - -fn id(x: u32) u32 { - return x; -} - -// TODO: The parameters to the asm statement in print() had to -// be in a specific order because otherwise the write to r0 -// would overwrite the len parameter which resides in r0 -fn print(len: u32) void { - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg3] "{r2}" (len), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("Hello, World!\n")), - : "memory" - ); - return; -} - -// run -// target=arm-linux -// -// Hello, World! -// diff --git a/test/cases/arm-linux/print_u32s.zig b/test/cases/arm-linux/print_u32s.zig @@ -1,40 +0,0 @@ -pub fn main() void { - printNumberHex(0x00000000); - printNumberHex(0xaaaaaaaa); - printNumberHex(0xdeadbeef); - printNumberHex(0x31415926); -} - -fn printNumberHex(x: u32) void { - var i: u5 = 28; - while (true) : (i -= 4) { - const digit = (x >> i) & 0xf; - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("0123456789abcdef") + digit), - [arg3] "{r2}" (1), - : "memory" - ); - - if (i == 0) break; - } - asm volatile ("svc #0" - : - : [number] "{r7}" (4), - [arg1] "{r0}" (1), - [arg2] "{r1}" (@ptrToInt("\n")), - [arg3] "{r2}" (1), - : "memory" - ); -} - -// run -// target=arm-linux -// -// 00000000 -// aaaaaaaa -// deadbeef -// 31415926 -// diff --git a/test/cases/arm-linux/spilling_registers.0.zig b/test/cases/arm-linux/spilling_registers.0.zig @@ -1,38 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 791); -} - -fn add(a: u32, b: u32) u32 { - const x: u32 = blk: { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - const f = d + e; // 24 - const g = e + f; // 38 - const h = f + g; // 62 - const i = g + h; // 100 - const j = i + d; // 110 - const k = i + j; // 210 - const l = k + c; // 217 - const m = l + d; // 227 - const n = m + e; // 241 - const o = n + f; // 265 - const p = o + g; // 303 - const q = p + h; // 365 - const r = q + i; // 465 - const s = r + j; // 575 - const t = s + k; // 785 - break :blk t; - }; - const y = x + a; // 788 - const z = y + a; // 791 - return z; -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// target=arm-linux -// diff --git a/test/cases/assert_function.0.zig b/test/cases/assert_function.0.zig @@ -0,0 +1,15 @@ +pub fn main() void { + add(3, 4); +} + +fn add(a: u32, b: u32) void { + assert(a + b == 7); +} + +pub fn assert(ok: bool) void { + if (!ok) unreachable; // assertion failure +} + +// run +// target=x86_64-macos,x86_64-linux +// link_libc=true diff --git a/test/cases/x86_64-linux/assert_function.1.zig b/test/cases/assert_function.1.zig diff --git a/test/cases/x86_64-linux/assert_function.10.zig b/test/cases/assert_function.10.zig diff --git a/test/cases/x86_64-linux/assert_function.11.zig b/test/cases/assert_function.11.zig diff --git a/test/cases/x86_64-linux/assert_function.12.zig b/test/cases/assert_function.12.zig diff --git a/test/cases/x86_64-linux/assert_function.13.zig b/test/cases/assert_function.13.zig diff --git a/test/cases/x86_64-linux/assert_function.14.zig b/test/cases/assert_function.14.zig diff --git a/test/cases/x86_64-linux/assert_function.15.zig b/test/cases/assert_function.15.zig diff --git a/test/cases/x86_64-linux/assert_function.16.zig b/test/cases/assert_function.16.zig diff --git a/test/cases/x86_64-linux/assert_function.17.zig b/test/cases/assert_function.17.zig diff --git a/test/cases/assert_function.18.zig b/test/cases/assert_function.18.zig @@ -0,0 +1,20 @@ +const builtin = @import("builtin"); + +extern "c" fn write(c_int, usize, usize) usize; + +pub fn main() void { + for ("hello") |_| print(); +} + +fn print() void { + _ = write(1, @ptrToInt("hello\n"), 6); +} + +// run +// +// hello +// hello +// hello +// hello +// hello +// diff --git a/test/cases/x86_64-linux/assert_function.2.zig b/test/cases/assert_function.2.zig diff --git a/test/cases/x86_64-linux/assert_function.3.zig b/test/cases/assert_function.3.zig diff --git a/test/cases/x86_64-linux/assert_function.4.zig b/test/cases/assert_function.4.zig diff --git a/test/cases/x86_64-linux/assert_function.5.zig b/test/cases/assert_function.5.zig diff --git a/test/cases/x86_64-linux/assert_function.6.zig b/test/cases/assert_function.6.zig diff --git a/test/cases/assert_function.7.zig b/test/cases/assert_function.7.zig @@ -0,0 +1,23 @@ +extern "c" fn write(c_int, usize, usize) usize; + +pub fn main() void { + var i: u32 = 0; + while (i < 4) : (i += 1) print(); + assert(i == 4); +} + +fn print() void { + _ = write(1, @ptrToInt("hello\n"), 6); +} + +pub fn assert(ok: bool) void { + if (!ok) unreachable; // assertion failure +} + +// run +// +// hello +// hello +// hello +// hello +// diff --git a/test/cases/assert_function.8.zig b/test/cases/assert_function.8.zig @@ -0,0 +1,20 @@ +extern "c" fn write(c_int, usize, usize) usize; + +pub fn main() void { + var i: u32 = 0; + inline while (i < 4) : (i += 1) print(); + assert(i == 4); +} + +fn print() void { + _ = write(1, @ptrToInt("hello\n"), 6); +} + +pub fn assert(ok: bool) void { + if (!ok) unreachable; // assertion failure +} + +// error +// +// :5:21: error: unable to resolve comptime value +// :5:21: note: condition in comptime branch must be comptime-known diff --git a/test/cases/x86_64-linux/assert_function.9.zig b/test/cases/assert_function.9.zig diff --git a/test/cases/break_continue.0.zig b/test/cases/break_continue.0.zig @@ -5,5 +5,5 @@ pub fn main() void { } // run -// target=x86_64-linux,x86_64-macos,aarch64-linux,aarch64-macos +// target=x86_64-linux,x86_64-macos // diff --git a/test/cases/comptime_var.0.zig b/test/cases/comptime_var.0.zig @@ -0,0 +1,13 @@ +pub fn main() void { + var a: u32 = 0; + comptime var b: u32 = 0; + if (a == 0) b = 3; +} + +// error +// output_mode=Exe +// target=x86_64-macos,x86_64-linux +// link_libc=true +// +// :4:19: error: store to comptime variable depends on runtime condition +// :4:11: note: runtime condition here diff --git a/test/cases/x86_64-linux/comptime_var.1.zig b/test/cases/comptime_var.1.zig diff --git a/test/cases/comptime_var.2.zig b/test/cases/comptime_var.2.zig @@ -0,0 +1,17 @@ +extern "c" fn write(c_int, usize, usize) usize; + +pub fn main() void { + comptime var len: u32 = 5; + print(len); + len += 9; + print(len); +} + +fn print(len: usize) void { + _ = write(1, @ptrToInt("Hello, World!\n"), len); +} + +// run +// +// HelloHello, World! +// diff --git a/test/cases/x86_64-linux/comptime_var.3.zig b/test/cases/comptime_var.3.zig diff --git a/test/cases/x86_64-linux/comptime_var.4.zig b/test/cases/comptime_var.4.zig diff --git a/test/cases/x86_64-linux/comptime_var.5.zig b/test/cases/comptime_var.5.zig diff --git a/test/cases/comptime_var.6.zig b/test/cases/comptime_var.6.zig @@ -0,0 +1,15 @@ +extern "c" fn write(c_int, usize, usize) usize; + +pub fn main() void { + comptime var i: u64 = 2; + inline while (i < 6) : (i += 1) { + print(i); + } +} +fn print(len: usize) void { + _ = write(1, @ptrToInt("Hello"), len); +} + +// run +// +// HeHelHellHello diff --git a/test/cases/conditional_branches.0.zig b/test/cases/conditional_branches.0.zig @@ -0,0 +1,23 @@ +extern "c" fn write(c_int, usize, usize) usize; + +pub fn main() void { + foo(123); +} + +fn foo(x: u64) void { + if (x > 42) { + print(); + } +} + +fn print() void { + const str = "Hello, World!\n"; + _ = write(1, @ptrToInt(str.ptr), ptr.len); +} + +// run +// target=x86_64-linux,x86_64-macos +// link_libc=true +// +// Hello, World! +// diff --git a/test/cases/conditional_branches.1.zig b/test/cases/conditional_branches.1.zig @@ -0,0 +1,25 @@ +extern "c" fn write(c_int, usize, usize) usize; + +pub fn main() void { + foo(true); +} + +fn foo(x: bool) void { + if (x) { + print(); + print(); + } else { + print(); + } +} + +fn print() void { + const str = "Hello, World!\n"; + _ = write(1, @ptrToInt(str.ptr), ptr.len); +} + +// run +// +// Hello, World! +// Hello, World! +// diff --git a/test/cases/wasm-wasi/conditions.0.zig b/test/cases/conditions.0.zig diff --git a/test/cases/wasm-wasi/conditions.1.zig b/test/cases/conditions.1.zig diff --git a/test/cases/wasm-wasi/conditions.2.zig b/test/cases/conditions.2.zig diff --git a/test/cases/wasm-wasi/conditions.3.zig b/test/cases/conditions.3.zig diff --git a/test/cases/wasm-wasi/conditions.4.zig b/test/cases/conditions.4.zig diff --git a/test/cases/wasm-wasi/conditions.5.zig b/test/cases/conditions.5.zig diff --git a/test/cases/wasm-wasi/error_unions.0.zig b/test/cases/error_unions.0.zig diff --git a/test/cases/wasm-wasi/error_unions.1.zig b/test/cases/error_unions.1.zig diff --git a/test/cases/wasm-wasi/error_unions.2.zig b/test/cases/error_unions.2.zig diff --git a/test/cases/wasm-wasi/error_unions.3.zig b/test/cases/error_unions.3.zig diff --git a/test/cases/wasm-wasi/error_unions.4.zig b/test/cases/error_unions.4.zig diff --git a/test/cases/wasm-wasi/error_unions.5.zig b/test/cases/error_unions.5.zig diff --git a/test/cases/errors.0.zig b/test/cases/errors.0.zig @@ -0,0 +1,15 @@ +const std = @import("std"); + +pub fn main() void { + foo() catch print(); +} + +fn foo() anyerror!void {} + +fn print() void { + _ = std.os.write(1, "Hello, World!\n") catch {}; +} + +// run +// target=x86_64-macos +// diff --git a/test/cases/errors.1.zig b/test/cases/errors.1.zig @@ -0,0 +1,18 @@ +const std = @import("std"); + +pub fn main() void { + foo() catch print(); +} + +fn foo() anyerror!void { + return error.Test; +} + +fn print() void { + _ = std.os.write(1, "Hello, World!\n") catch {}; +} + +// run +// +// Hello, World! +// diff --git a/test/cases/arm-linux/errors.2.zig b/test/cases/errors.2.zig diff --git a/test/cases/arm-linux/errors.3.zig b/test/cases/errors.3.zig diff --git a/test/cases/exit.zig b/test/cases/exit.zig @@ -0,0 +1,5 @@ +pub fn main() void {} + +// run +// target=x86_64-linux,x86_64-macos,x86_64-windows,x86_64-plan9 +// diff --git a/test/cases/function_pointers.zig b/test/cases/function_pointers.zig @@ -0,0 +1,30 @@ +const std = @import("std"); + +const PrintFn = *const fn () void; + +pub fn main() void { + var printFn: PrintFn = stopSayingThat; + var i: u32 = 0; + while (i < 4) : (i += 1) printFn(); + + printFn = moveEveryZig; + printFn(); +} + +fn stopSayingThat() void { + _ = std.os.write(1, "Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n") catch {}; +} + +fn moveEveryZig() void { + _ = std.os.write(1, "All your codebase are belong to us\n") catch {}; +} + +// run +// target=x86_64-macos +// +// Hello, my name is Inigo Montoya; you killed my father, prepare to die. +// Hello, my name is Inigo Montoya; you killed my father, prepare to die. +// Hello, my name is Inigo Montoya; you killed my father, prepare to die. +// Hello, my name is Inigo Montoya; you killed my father, prepare to die. +// All your codebase are belong to us +// diff --git a/test/cases/hello_world_with_updates.0.zig b/test/cases/hello_world_with_updates.0.zig @@ -0,0 +1,6 @@ +// error +// output_mode=Exe +// target=x86_64-linux,x86_64-macos +// link_libc=true +// +// :?:?: error: root struct of file 'tmp' has no member named 'main' diff --git a/test/cases/aarch64-macos/hello_world_with_updates.1.zig b/test/cases/hello_world_with_updates.1.zig diff --git a/test/cases/hello_world_with_updates.2.zig b/test/cases/hello_world_with_updates.2.zig @@ -0,0 +1,19 @@ +extern "c" fn write(c_int, usize, usize) usize; +extern "c" fn exit(c_int) noreturn; + +pub export fn main() noreturn { + print(); + + exit(0); +} + +fn print() void { + const msg = @ptrToInt("Hello, World!\n"); + const len = 14; + _ = write(1, msg, len); +} + +// run +// +// Hello, World! +// diff --git a/test/cases/hello_world_with_updates.3.zig b/test/cases/hello_world_with_updates.3.zig @@ -0,0 +1,16 @@ +extern "c" fn write(c_int, usize, usize) usize; + +pub fn main() void { + print(); +} + +fn print() void { + const msg = @ptrToInt("Hello, World!\n"); + const len = 14; + _ = write(1, msg, len); +} + +// run +// +// Hello, World! +// diff --git a/test/cases/hello_world_with_updates.4.zig b/test/cases/hello_world_with_updates.4.zig @@ -0,0 +1,22 @@ +extern "c" fn write(c_int, usize, usize) usize; + +pub fn main() void { + print(); + print(); + print(); + print(); +} + +fn print() void { + const msg = @ptrToInt("Hello, World!\n"); + const len = 14; + _ = write(1, msg, len); +} + +// run +// +// Hello, World! +// Hello, World! +// Hello, World! +// Hello, World! +// diff --git a/test/cases/hello_world_with_updates.5.zig b/test/cases/hello_world_with_updates.5.zig @@ -0,0 +1,16 @@ +extern "c" fn write(c_int, usize, usize) usize; + +pub fn main() void { + print(); +} + +fn print() void { + const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); + const len = 104; + _ = write(1, msg, len); +} + +// run +// +// What is up? This is a longer message that will force the data to be relocated in virtual address space. +// diff --git a/test/cases/hello_world_with_updates.6.zig b/test/cases/hello_world_with_updates.6.zig @@ -0,0 +1,20 @@ +const builtin = @import("builtin"); + +extern "c" fn write(c_int, usize, usize) usize; + +pub fn main() void { + print(); + print(); +} + +fn print() void { + const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); + const len = 104; + _ = write(1, msg, len); +} + +// run +// +// What is up? This is a longer message that will force the data to be relocated in virtual address space. +// What is up? This is a longer message that will force the data to be relocated in virtual address space. +// diff --git a/test/cases/large_add_function.zig b/test/cases/large_add_function.zig @@ -33,6 +33,8 @@ fn assert(ok: bool) void { if (!ok) unreachable; } +// TODO: enable this for native backend + // run +// backend=llvm // target=aarch64-linux,aarch64-macos -// diff --git a/test/cases/wasm-wasi/locals.0.zig b/test/cases/locals.0.zig diff --git a/test/cases/wasm-wasi/locals.1.zig b/test/cases/locals.1.zig diff --git a/test/cases/only_1_function_and_it_gets_updated.0.zig b/test/cases/only_1_function_and_it_gets_updated.0.zig @@ -0,0 +1,7 @@ +pub export fn _start() noreturn { + while (true) {} +} + +// run +// target=x86_64-linux,x86_64-macos +// diff --git a/test/cases/only_1_function_and_it_gets_updated.1.zig b/test/cases/only_1_function_and_it_gets_updated.1.zig @@ -0,0 +1,8 @@ +pub export fn _start() noreturn { + var dummy: u32 = 10; + _ = dummy; + while (true) {} +} + +// run +// diff --git a/test/cases/wasm-wasi/optionals.0.zig b/test/cases/optionals.0.zig diff --git a/test/cases/wasm-wasi/optionals.1.zig b/test/cases/optionals.1.zig diff --git a/test/cases/wasm-wasi/optionals.2.zig b/test/cases/optionals.2.zig diff --git a/test/cases/wasm-wasi/optionals.3.zig b/test/cases/optionals.3.zig diff --git a/test/cases/wasm-wasi/optionals.4.zig b/test/cases/optionals.4.zig diff --git a/test/cases/parameters_and_return_values.0.zig b/test/cases/parameters_and_return_values.0.zig @@ -0,0 +1,20 @@ +const std = @import("std"); + +pub fn main() void { + print(id(14)); +} + +fn id(x: u32) u32 { + return x; +} + +fn print(len: u32) void { + const str = "Hello, World!\n"; + _ = std.os.write(1, str[0..len]) catch {}; +} + +// run +// target=x86_64-macos +// +// Hello, World! +// diff --git a/test/cases/arm-linux/parameters_and_return_values.1.zig b/test/cases/parameters_and_return_values.1.zig diff --git a/test/cases/plan9/exit.zig b/test/cases/plan9/exit.zig @@ -1,5 +0,0 @@ -pub fn main() void {} - -// run -// target=x86_64-plan9 -// diff --git a/test/cases/plan9/hello_world_with_updates.0.zig b/test/cases/plan9/hello_world_with_updates.0.zig @@ -1,28 +0,0 @@ -pub fn main() void { - const str = "Hello World!\n"; - asm volatile ( - \\push $0 - \\push %%r10 - \\push %%r11 - \\push $1 - \\push $0 - \\syscall - \\pop %%r11 - \\pop %%r11 - \\pop %%r11 - \\pop %%r11 - \\pop %%r11 - : - // pwrite - : [syscall_number] "{rbp}" (51), - [hey] "{r11}" (@ptrToInt(str)), - [strlen] "{r10}" (str.len), - : "rcx", "rbp", "r11", "memory" - ); -} - -// run -// target=x86_64-plan9 -// -// Hello World -// diff --git a/test/cases/plan9/hello_world_with_updates.1.zig b/test/cases/plan9/hello_world_with_updates.1.zig @@ -1,11 +0,0 @@ -const std = @import("std"); -pub fn main() void { - const str = "Hello World!\n"; - _ = std.os.plan9.pwrite(1, str, str.len, 0); -} - -// run -// target=x86_64-plan9 -// -// Hello World -// diff --git a/test/cases/wasm-wasi/pointers.0.zig b/test/cases/pointers.0.zig diff --git a/test/cases/wasm-wasi/pointers.1.zig b/test/cases/pointers.1.zig diff --git a/test/cases/print_u32s.zig b/test/cases/print_u32s.zig @@ -0,0 +1,28 @@ +const std = @import("std"); + +pub fn main() void { + printNumberHex(0x00000000); + printNumberHex(0xaaaaaaaa); + printNumberHex(0xdeadbeef); + printNumberHex(0x31415926); +} + +fn printNumberHex(x: u32) void { + const digit_chars = "0123456789abcdef"; + var i: u5 = 28; + while (true) : (i -= 4) { + const digit = (x >> i) & 0xf; + _ = std.os.write(1, &.{digit_chars[digit]}) catch {}; + if (i == 0) break; + } + _ = std.os.write(1, "\n") catch {}; +} + +// run +// target=x86_64-macos +// +// 00000000 +// aaaaaaaa +// deadbeef +// 31415926 +// diff --git a/test/cases/recursive_fibonacci.zig b/test/cases/recursive_fibonacci.zig @@ -20,5 +20,5 @@ fn assert(ok: bool) void { } // run -// target=x86_64-linux,x86_64-macos,arm-linux,wasm32-wasi +// target=x86_64-linux,x86_64-macos,wasm32-wasi // diff --git a/test/cases/spilling_registers.0.zig b/test/cases/spilling_registers.0.zig @@ -0,0 +1,38 @@ +pub fn main() void { + assert(add(3, 4) == 791); +} + +fn add(a: u32, b: u32) u32 { + const x: u32 = blk: { + const c = a + b; // 7 + const d = a + c; // 10 + const e = d + b; // 14 + const f = d + e; // 24 + const g = e + f; // 38 + const h = f + g; // 62 + const i = g + h; // 100 + const j = i + d; // 110 + const k = i + j; // 210 + const l = k + c; // 217 + const m = l + d; // 227 + const n = m + e; // 241 + const o = n + f; // 265 + const p = o + g; // 303 + const q = p + h; // 365 + const r = q + i; // 465 + const s = r + j; // 575 + const t = s + k; // 785 + break :blk t; + }; + const y = x + a; // 788 + const z = y + a; // 791 + return z; +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// target=x86_64-linux,x86_64-macos +// diff --git a/test/cases/arm-linux/spilling_registers.1.zig b/test/cases/spilling_registers.1.zig diff --git a/test/cases/wasm-wasi/structs.0.zig b/test/cases/structs.0.zig diff --git a/test/cases/wasm-wasi/structs.1.zig b/test/cases/structs.1.zig diff --git a/test/cases/wasm-wasi/structs.2.zig b/test/cases/structs.2.zig diff --git a/test/cases/wasm-wasi/structs.3.zig b/test/cases/structs.3.zig diff --git a/test/cases/wasm-wasi/structs.4.zig b/test/cases/structs.4.zig diff --git a/test/cases/wasm-wasi/switch.0.zig b/test/cases/switch.0.zig diff --git a/test/cases/wasm-wasi/switch.1.zig b/test/cases/switch.1.zig diff --git a/test/cases/wasm-wasi/switch.2.zig b/test/cases/switch.2.zig diff --git a/test/cases/wasm-wasi/switch.3.zig b/test/cases/switch.3.zig diff --git a/test/cases/wasm-wasi/while_loops.0.zig b/test/cases/while_loops.0.zig diff --git a/test/cases/wasm-wasi/while_loops.1.zig b/test/cases/while_loops.1.zig diff --git a/test/cases/wasm-wasi/while_loops.2.zig b/test/cases/while_loops.2.zig diff --git a/test/cases/x86_64-linux/assert_function.0.zig b/test/cases/x86_64-linux/assert_function.0.zig @@ -1,15 +0,0 @@ -pub fn main() void { - add(3, 4); -} - -fn add(a: u32, b: u32) void { - assert(a + b == 7); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// target=x86_64-linux -// diff --git a/test/cases/x86_64-linux/assert_function.18.zig b/test/cases/x86_64-linux/assert_function.18.zig @@ -1,35 +0,0 @@ -const builtin = @import("builtin"); - -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - for ("hello") |_| print(); -} - -fn print() void { - switch (builtin.os.tag) { - .linux => { - asm volatile ("syscall" - : - : [number] "{rax}" (1), - [arg1] "{rdi}" (1), - [arg2] "{rsi}" (@ptrToInt("hello\n")), - [arg3] "{rdx}" (6), - : "rcx", "r11", "memory" - ); - }, - .macos => { - _ = write(1, @ptrToInt("hello\n"), 6); - }, - else => unreachable, - } -} - -// run -// -// hello -// hello -// hello -// hello -// hello -// diff --git a/test/cases/x86_64-linux/assert_function.7.zig b/test/cases/x86_64-linux/assert_function.7.zig @@ -1,28 +0,0 @@ -pub fn main() void { - var i: u32 = 0; - while (i < 4) : (i += 1) print(); - assert(i == 4); -} - -fn print() void { - asm volatile ("syscall" - : - : [number] "{rax}" (1), - [arg1] "{rdi}" (1), - [arg2] "{rsi}" (@ptrToInt("hello\n")), - [arg3] "{rdx}" (6), - : "rcx", "r11", "memory" - ); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// -// hello -// hello -// hello -// hello -// diff --git a/test/cases/x86_64-linux/assert_function.8.zig b/test/cases/x86_64-linux/assert_function.8.zig @@ -1,25 +0,0 @@ -pub fn main() void { - var i: u32 = 0; - inline while (i < 4) : (i += 1) print(); - assert(i == 4); -} - -fn print() void { - asm volatile ("syscall" - : - : [number] "{rax}" (1), - [arg1] "{rdi}" (1), - [arg2] "{rsi}" (@ptrToInt("hello\n")), - [arg3] "{rdx}" (6), - : "rcx", "r11", "memory" - ); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// error -// -// :3:21: error: unable to resolve comptime value -// :3:21: note: condition in comptime branch must be comptime-known diff --git a/test/cases/x86_64-linux/comptime_var.0.zig b/test/cases/x86_64-linux/comptime_var.0.zig @@ -1,12 +0,0 @@ -pub fn main() void { - var a: u32 = 0; - comptime var b: u32 = 0; - if (a == 0) b = 3; -} - -// error -// output_mode=Exe -// target=x86_64-linux -// -// :4:19: error: store to comptime variable depends on runtime condition -// :4:11: note: runtime condition here diff --git a/test/cases/x86_64-linux/comptime_var.2.zig b/test/cases/x86_64-linux/comptime_var.2.zig @@ -1,22 +0,0 @@ -pub fn main() void { - comptime var len: u32 = 5; - print(len); - len += 9; - print(len); -} - -fn print(len: usize) void { - asm volatile ("syscall" - : - : [number] "{rax}" (1), - [arg1] "{rdi}" (1), - [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")), - [arg3] "{rdx}" (len), - : "rcx", "r11", "memory" - ); -} - -// run -// -// HelloHello, World! -// diff --git a/test/cases/x86_64-linux/comptime_var.6.zig b/test/cases/x86_64-linux/comptime_var.6.zig @@ -1,20 +0,0 @@ -pub fn main() void { - comptime var i: u64 = 2; - inline while (i < 6) : (i += 1) { - print(i); - } -} -fn print(len: usize) void { - asm volatile ("syscall" - : - : [number] "{rax}" (1), - [arg1] "{rdi}" (1), - [arg2] "{rsi}" (@ptrToInt("Hello")), - [arg3] "{rdx}" (len), - : "rcx", "r11", "memory" - ); -} - -// run -// -// HeHelHellHello diff --git a/test/cases/x86_64-linux/hello_world_with_updates.0.zig b/test/cases/x86_64-linux/hello_world_with_updates.0.zig @@ -1,8 +0,0 @@ -// error -// output_mode=Exe -// target=x86_64-linux -// -// :?:?: error: root struct of file 'tmp' has no member named 'main' -// :?:?: note: called from here -// :?:?: note: called from here -// :?:?: note: called from here diff --git a/test/cases/x86_64-linux/hello_world_with_updates.1.zig b/test/cases/x86_64-linux/hello_world_with_updates.1.zig @@ -1,6 +0,0 @@ -pub export fn main() noreturn {} - -// error -// -// :1:22: error: function declared 'noreturn' implicitly returns -// :1:32: note: control flow reaches end of body here diff --git a/test/cases/x86_64-linux/hello_world_with_updates.2.zig b/test/cases/x86_64-linux/hello_world_with_updates.2.zig @@ -1,32 +0,0 @@ -pub export fn _start() noreturn { - print(); - - exit(); -} - -fn print() void { - asm volatile ("syscall" - : - : [number] "{rax}" (1), - [arg1] "{rdi}" (1), - [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")), - [arg3] "{rdx}" (14), - : "rcx", "r11", "memory" - ); - return; -} - -fn exit() noreturn { - asm volatile ("syscall" - : - : [number] "{rax}" (231), - [arg1] "{rdi}" (0), - : "rcx", "r11", "memory" - ); - unreachable; -} - -// run -// -// Hello, World! -// diff --git a/test/cases/x86_64-linux/hello_world_with_updates.3.zig b/test/cases/x86_64-linux/hello_world_with_updates.3.zig @@ -1,20 +0,0 @@ -pub fn main() void { - print(); -} - -fn print() void { - asm volatile ("syscall" - : - : [number] "{rax}" (1), - [arg1] "{rdi}" (1), - [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")), - [arg3] "{rdx}" (14), - : "rcx", "r11", "memory" - ); - return; -} - -// run -// -// Hello, World! -// diff --git a/test/cases/x86_64-linux/hello_world_with_updates.4.zig b/test/cases/x86_64-linux/hello_world_with_updates.4.zig @@ -1,20 +0,0 @@ -pub fn main() void { - print(); -} - -fn print() void { - asm volatile ("syscall" - : - : [number] "{rax}" (1), - [arg1] "{rdi}" (1), - [arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")), - [arg3] "{rdx}" (104), - : "rcx", "r11", "memory" - ); - return; -} - -// run -// -// What is up? This is a longer message that will force the data to be relocated in virtual address space. -// diff --git a/test/cases/x86_64-linux/hello_world_with_updates.5.zig b/test/cases/x86_64-linux/hello_world_with_updates.5.zig @@ -1,22 +0,0 @@ -pub fn main() void { - print(); - print(); -} - -fn print() void { - asm volatile ("syscall" - : - : [number] "{rax}" (1), - [arg1] "{rdi}" (1), - [arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")), - [arg3] "{rdx}" (104), - : "rcx", "r11", "memory" - ); - return; -} - -// run -// -// What is up? This is a longer message that will force the data to be relocated in virtual address space. -// What is up? This is a longer message that will force the data to be relocated in virtual address space. -// diff --git a/test/cases/x86_64-linux/only_1_function_and_it_gets_updated.0.zig b/test/cases/x86_64-linux/only_1_function_and_it_gets_updated.0.zig @@ -1,13 +0,0 @@ -pub export fn _start() noreturn { - asm volatile ("syscall" - : - : [number] "{rax}" (60), // exit - [arg1] "{rdi}" (0), - : "rcx", "r11", "memory" - ); - unreachable; -} - -// run -// target=x86_64-linux -// diff --git a/test/cases/x86_64-linux/only_1_function_and_it_gets_updated.1.zig b/test/cases/x86_64-linux/only_1_function_and_it_gets_updated.1.zig @@ -1,12 +0,0 @@ -pub export fn _start() noreturn { - asm volatile ("syscall" - : - : [number] "{rax}" (231), // exit_group - [arg1] "{rdi}" (0), - : "rcx", "r11", "memory" - ); - unreachable; -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.0.zig b/test/cases/x86_64-macos/assert_function.0.zig @@ -1,15 +0,0 @@ -pub fn main() void { - add(3, 4); -} - -fn add(a: u32, b: u32) void { - assert(a + b == 7); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// target=x86_64-macos -// diff --git a/test/cases/x86_64-macos/assert_function.1.zig b/test/cases/x86_64-macos/assert_function.1.zig @@ -1,17 +0,0 @@ -pub fn main() void { - add(3, 4); -} - -fn add(a: u32, b: u32) void { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - assert(e == 14); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.10.zig b/test/cases/x86_64-macos/assert_function.10.zig @@ -1,27 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 116); -} - -fn add(a: u32, b: u32) u32 { - const x: u32 = blk: { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - const f = d + e; // 24 - const g = e + f; // 38 - const h = f + g; // 62 - const i = g + h; // 100 - const j = i + d; // 110 - break :blk j; - }; - const y = x + a; // 113 - const z = y + a; // 116 - return z; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.11.zig b/test/cases/x86_64-macos/assert_function.11.zig @@ -1,66 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 1221); - assert(mul(3, 4) == 21609); -} - -fn add(a: u32, b: u32) u32 { - const x: u32 = blk: { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - const f = d + e; // 24 - const g = e + f; // 38 - const h = f + g; // 62 - const i = g + h; // 100 - const j = i + d; // 110 - const k = i + j; // 210 - const l = j + k; // 320 - const m = l + c; // 327 - const n = m + d; // 337 - const o = n + e; // 351 - const p = o + f; // 375 - const q = p + g; // 413 - const r = q + h; // 475 - const s = r + i; // 575 - const t = s + j; // 685 - const u = t + k; // 895 - const v = u + l; // 1215 - break :blk v; - }; - const y = x + a; // 1218 - const z = y + a; // 1221 - return z; -} - -fn mul(a: u32, b: u32) u32 { - const x: u32 = blk: { - const c = a * a * a * a; // 81 - const d = a * a * a * b; // 108 - const e = a * a * b * a; // 108 - const f = a * a * b * b; // 144 - const g = a * b * a * a; // 108 - const h = a * b * a * b; // 144 - const i = a * b * b * a; // 144 - const j = a * b * b * b; // 192 - const k = b * a * a * a; // 108 - const l = b * a * a * b; // 144 - const m = b * a * b * a; // 144 - const n = b * a * b * b; // 192 - const o = b * b * a * a; // 144 - const p = b * b * a * b; // 192 - const q = b * b * b * a; // 192 - const r = b * b * b * b; // 256 - const s = c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r; // 2401 - break :blk s; - }; - const y = x * a; // 7203 - const z = y * a; // 21609 - return z; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.12.zig b/test/cases/x86_64-macos/assert_function.12.zig @@ -1,47 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 791); - assert(add(4, 3) == 79); -} - -fn add(a: u32, b: u32) u32 { - const x: u32 = if (a < b) blk: { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - const f = d + e; // 24 - const g = e + f; // 38 - const h = f + g; // 62 - const i = g + h; // 100 - const j = i + d; // 110 - const k = i + j; // 210 - const l = k + c; // 217 - const m = l + d; // 227 - const n = m + e; // 241 - const o = n + f; // 265 - const p = o + g; // 303 - const q = p + h; // 365 - const r = q + i; // 465 - const s = r + j; // 575 - const t = s + k; // 785 - break :blk t; - } else blk: { - const t = b + b + a; // 10 - const c = a + t; // 14 - const d = c + t; // 24 - const e = d + t; // 34 - const f = e + t; // 44 - const g = f + t; // 54 - const h = c + g; // 68 - break :blk h + b; // 71 - }; - const y = x + a; // 788, 75 - const z = y + a; // 791, 79 - return z; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.13.zig b/test/cases/x86_64-macos/assert_function.13.zig @@ -1,19 +0,0 @@ -pub fn main() void { - const ignore = - \\ cool thx - \\ - ; - _ = ignore; - add('ぁ', '\x03'); -} - -fn add(a: u32, b: u32) void { - assert(a + b == 12356); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.14.zig b/test/cases/x86_64-macos/assert_function.14.zig @@ -1,17 +0,0 @@ -pub fn main() void { - add(aa, bb); -} - -const aa = 'ぁ'; -const bb = '\x03'; - -fn add(a: u32, b: u32) void { - assert(a + b == 12356); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.15.zig b/test/cases/x86_64-macos/assert_function.15.zig @@ -1,10 +0,0 @@ -pub fn main() void { - assert("hello"[0] == 'h'); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.16.zig b/test/cases/x86_64-macos/assert_function.16.zig @@ -1,11 +0,0 @@ -const hello = "hello".*; -pub fn main() void { - assert(hello[1] == 'e'); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.17.zig b/test/cases/x86_64-macos/assert_function.17.zig @@ -1,11 +0,0 @@ -pub fn main() void { - var i: u64 = 0xFFEEDDCCBBAA9988; - assert(i == 0xFFEEDDCCBBAA9988); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.18.zig b/test/cases/x86_64-macos/assert_function.18.zig @@ -1,35 +0,0 @@ -const builtin = @import("builtin"); - -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - for ("hello") |_| print(); -} - -fn print() void { - switch (builtin.os.tag) { - .linux => { - asm volatile ("syscall" - : - : [number] "{rax}" (1), - [arg1] "{rdi}" (1), - [arg2] "{rsi}" (@ptrToInt("hello\n")), - [arg3] "{rdx}" (6), - : "rcx", "r11", "memory" - ); - }, - .macos => { - _ = write(1, @ptrToInt("hello\n"), 6); - }, - else => unreachable, - } -} - -// run -// -// hello -// hello -// hello -// hello -// hello -// diff --git a/test/cases/x86_64-macos/assert_function.2.zig b/test/cases/x86_64-macos/assert_function.2.zig @@ -1,21 +0,0 @@ -pub fn main() void { - add(3, 4); -} - -fn add(a: u32, b: u32) void { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - const f = d + e; // 24 - const g = e + f; // 38 - const h = f + g; // 62 - const i = g + h; // 100 - assert(i == 100); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.3.zig b/test/cases/x86_64-macos/assert_function.3.zig @@ -1,22 +0,0 @@ -pub fn main() void { - add(3, 4); -} - -fn add(a: u32, b: u32) void { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - const f = d + e; // 24 - const g = e + f; // 38 - const h = f + g; // 62 - const i = g + h; // 100 - const j = i + d; // 110 - assert(j == 110); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.4.zig b/test/cases/x86_64-macos/assert_function.4.zig @@ -1,15 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 7); - assert(add(20, 10) == 30); -} - -fn add(a: u32, b: u32) u32 { - return a + b; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.5.zig b/test/cases/x86_64-macos/assert_function.5.zig @@ -1,19 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 7); - assert(add(20, 10) == 30); -} - -fn add(a: u32, b: u32) u32 { - var x: u32 = undefined; - x = 0; - x += a; - x += b; - return x; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.6.zig b/test/cases/x86_64-macos/assert_function.6.zig @@ -1,9 +0,0 @@ -pub fn main() void { - const a: u32 = 2; - const b: ?u32 = a; - const c = b.?; - if (c != 2) unreachable; -} - -// run -// diff --git a/test/cases/x86_64-macos/assert_function.7.zig b/test/cases/x86_64-macos/assert_function.7.zig @@ -1,23 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - var i: u32 = 0; - while (i < 4) : (i += 1) print(); - assert(i == 4); -} - -fn print() void { - _ = write(1, @ptrToInt("hello\n"), 6); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// -// hello -// hello -// hello -// hello -// diff --git a/test/cases/x86_64-macos/assert_function.8.zig b/test/cases/x86_64-macos/assert_function.8.zig @@ -1,20 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - var i: u32 = 0; - inline while (i < 4) : (i += 1) print(); - assert(i == 4); -} - -fn print() void { - _ = write(1, @ptrToInt("hello\n"), 6); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// error -// -// :5:21: error: unable to resolve comptime value -// :5:21: note: condition in comptime branch must be comptime-known diff --git a/test/cases/x86_64-macos/assert_function.9.zig b/test/cases/x86_64-macos/assert_function.9.zig @@ -1,22 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 20); -} - -fn add(a: u32, b: u32) u32 { - const x: u32 = blk: { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - break :blk e; - }; - const y = x + a; // 17 - const z = y + a; // 20 - return z; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/x86_64-macos/comptime_var.0.zig b/test/cases/x86_64-macos/comptime_var.0.zig @@ -1,12 +0,0 @@ -pub fn main() void { - var a: u32 = 0; - comptime var b: u32 = 0; - if (a == 0) b = 3; -} - -// error -// output_mode=Exe -// target=x86_64-macos -// -// :4:19: error: store to comptime variable depends on runtime condition -// :4:11: note: runtime condition here diff --git a/test/cases/x86_64-macos/comptime_var.1.zig b/test/cases/x86_64-macos/comptime_var.1.zig @@ -1,13 +0,0 @@ -pub fn main() void { - var a: u32 = 0; - comptime var b: u32 = 0; - switch (a) { - 0 => {}, - else => b = 3, - } -} - -// error -// -// :6:19: error: store to comptime variable depends on runtime condition -// :4:13: note: runtime condition here diff --git a/test/cases/x86_64-macos/comptime_var.2.zig b/test/cases/x86_64-macos/comptime_var.2.zig @@ -1,17 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - comptime var len: u32 = 5; - print(len); - len += 9; - print(len); -} - -fn print(len: usize) void { - _ = write(1, @ptrToInt("Hello, World!\n"), len); -} - -// run -// -// HelloHello, World! -// diff --git a/test/cases/x86_64-macos/comptime_var.3.zig b/test/cases/x86_64-macos/comptime_var.3.zig @@ -1,10 +0,0 @@ -comptime { - var x: i32 = 1; - x += 1; - if (x != 1) unreachable; -} -pub fn main() void {} - -// error -// -// :4:17: error: reached unreachable code diff --git a/test/cases/x86_64-macos/comptime_var.4.zig b/test/cases/x86_64-macos/comptime_var.4.zig @@ -1,9 +0,0 @@ -pub fn main() void { - comptime var i: u64 = 0; - while (i < 5) : (i += 1) {} -} - -// error -// -// :3:24: error: cannot store to comptime variable in non-inline loop -// :3:5: note: non-inline loop here diff --git a/test/cases/x86_64-macos/comptime_var.5.zig b/test/cases/x86_64-macos/comptime_var.5.zig @@ -1,15 +0,0 @@ -pub fn main() void { - var a: u32 = 0; - if (a == 0) { - comptime var b: u32 = 0; - b = 1; - } -} -comptime { - var x: i32 = 1; - x += 1; - if (x != 2) unreachable; -} - -// run -// diff --git a/test/cases/x86_64-macos/comptime_var.6.zig b/test/cases/x86_64-macos/comptime_var.6.zig @@ -1,15 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - comptime var i: u64 = 2; - inline while (i < 6) : (i += 1) { - print(i); - } -} -fn print(len: usize) void { - _ = write(1, @ptrToInt("Hello"), len); -} - -// run -// -// HeHelHellHello diff --git a/test/cases/x86_64-macos/hello_world_with_updates.0.zig b/test/cases/x86_64-macos/hello_world_with_updates.0.zig @@ -1,5 +0,0 @@ -// error -// output_mode=Exe -// target=x86_64-macos -// -// :?:?: error: root struct of file 'tmp' has no member named 'main' diff --git a/test/cases/x86_64-macos/hello_world_with_updates.1.zig b/test/cases/x86_64-macos/hello_world_with_updates.1.zig @@ -1,6 +0,0 @@ -pub export fn main() noreturn {} - -// error -// -// :1:22: error: function declared 'noreturn' implicitly returns -// :1:32: note: control flow reaches end of body here diff --git a/test/cases/x86_64-macos/hello_world_with_updates.2.zig b/test/cases/x86_64-macos/hello_world_with_updates.2.zig @@ -1,19 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; -extern "c" fn exit(usize) noreturn; - -pub export fn main() noreturn { - print(); - - exit(0); -} - -fn print() void { - const msg = @ptrToInt("Hello, World!\n"); - const len = 14; - _ = write(1, msg, len); -} - -// run -// -// Hello, World! -// diff --git a/test/cases/x86_64-macos/hello_world_with_updates.3.zig b/test/cases/x86_64-macos/hello_world_with_updates.3.zig @@ -1,16 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - print(); -} - -fn print() void { - const msg = @ptrToInt("Hello, World!\n"); - const len = 14; - _ = write(1, msg, len); -} - -// run -// -// Hello, World! -// diff --git a/test/cases/x86_64-macos/hello_world_with_updates.4.zig b/test/cases/x86_64-macos/hello_world_with_updates.4.zig @@ -1,22 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - print(); - print(); - print(); - print(); -} - -fn print() void { - const msg = @ptrToInt("Hello, World!\n"); - const len = 14; - _ = write(1, msg, len); -} - -// run -// -// Hello, World! -// Hello, World! -// Hello, World! -// Hello, World! -// diff --git a/test/cases/x86_64-macos/hello_world_with_updates.5.zig b/test/cases/x86_64-macos/hello_world_with_updates.5.zig @@ -1,16 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - print(); -} - -fn print() void { - const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); - const len = 104; - _ = write(1, msg, len); -} - -// run -// -// What is up? This is a longer message that will force the data to be relocated in virtual address space. -// diff --git a/test/cases/x86_64-macos/hello_world_with_updates.6.zig b/test/cases/x86_64-macos/hello_world_with_updates.6.zig @@ -1,18 +0,0 @@ -extern "c" fn write(usize, usize, usize) usize; - -pub fn main() void { - print(); - print(); -} - -fn print() void { - const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); - const len = 104; - _ = write(1, msg, len); -} - -// run -// -// What is up? This is a longer message that will force the data to be relocated in virtual address space. -// What is up? This is a longer message that will force the data to be relocated in virtual address space. -// diff --git a/test/cases/x86_64-windows/hello_world_with_updates.0.zig b/test/cases/x86_64-windows/hello_world_with_updates.0.zig @@ -1,7 +0,0 @@ -// error -// output_mode=Exe -// target=x86_64-windows -// -// :?:?: error: root struct of file 'tmp' has no member named 'main' -// :?:?: note: called from here -// :?:?: note: called from here diff --git a/test/cases/x86_64-windows/hello_world_with_updates.1.zig b/test/cases/x86_64-windows/hello_world_with_updates.1.zig @@ -1,6 +0,0 @@ -pub export fn main() noreturn {} - -// error -// -// :1:22: error: function declared 'noreturn' implicitly returns -// :1:32: note: control flow reaches end of body here diff --git a/test/cases/x86_64-windows/hello_world_with_updates.2.zig b/test/cases/x86_64-windows/hello_world_with_updates.2.zig @@ -1,16 +0,0 @@ -const std = @import("std"); - -pub fn main() void { - print(); -} - -fn print() void { - const msg = "Hello, World!\n"; - const stdout = std.io.getStdOut(); - stdout.writeAll(msg) catch unreachable; -} - -// run -// -// Hello, World! -//