authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-09-16 16:13:34+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-09-16 23:39:29+02:00
log4dba253cd2b22811c414aa0c183cf371bd111a57
tree2b4c357da6bc672ccbf4dea0d3e39e125c0d3c81
parent589e564f16fd9c07dde9ae88910219d25b7a377f
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

test: pull tests in test/cases/llvm/ up to test/cases/

There is nothing inherently LLVM-specific about any of these.

38 files changed, 351 insertions(+), 351 deletions(-)

test/cases/address_space_pointer_access_chaining_pointer_to_optional_array.zig created+12
...@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.gs) ?[1]i32) *addrspace(.gs) i32 {
2 return &a.*.?[0];
3}
4pub fn main() void {
5 _ = &entry;
6}
7
8// compile
9// output_mode=Exe
10// backend=selfhosted,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/address_spaces_pointer_access_chaining_array_pointer.zig created+12
...@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.gs) [1]i32) *addrspace(.gs) i32 {
2 return &a[0];
3}
4pub fn main() void {
5 _ = &entry;
6}
7
8// compile
9// output_mode=Exe
10// backend=selfhosted,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/address_spaces_pointer_access_chaining_complex.zig created+13
...@@ -0,0 +1,13 @@
1const A = struct { a: ?[1]i32 };
2fn entry(a: *addrspace(.gs) [1]A) *addrspace(.gs) i32 {
3 return &a[0].a.?[0];
4}
5pub fn main() void {
6 _ = &entry;
7}
8
9// compile
10// output_mode=Exe
11// backend=selfhosted,llvm
12// target=x86_64-linux,x86_64-macos
13//
test/cases/address_spaces_pointer_access_chaining_struct_pointer.zig created+13
...@@ -0,0 +1,13 @@
1const A = struct { a: i32 };
2fn entry(a: *addrspace(.gs) A) *addrspace(.gs) i32 {
3 return &a.a;
4}
5pub fn main() void {
6 _ = &entry;
7}
8
9// compile
10// output_mode=Exe
11// backend=selfhosted,llvm
12// target=x86_64-linux,x86_64-macos
13//
test/cases/blocks.zig created+23
...@@ -0,0 +1,23 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn foo(ok: bool) i32 {
6 const val: i32 = blk: {
7 var x: i32 = 1;
8 _ = &x;
9 if (!ok) break :blk x + 9;
10 break :blk x + 19;
11 };
12 return val + 10;
13}
14
15pub fn main() void {
16 assert(foo(false) == 20);
17 assert(foo(true) == 30);
18}
19
20// run
21// backend=selfhosted,llvm
22// target=x86_64-linux,x86_64-macos
23//
test/cases/dereferencing_though_multiple_pointers_with_address_spaces.zig created+12
...@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.fs) *addrspace(.gs) *i32) *i32 {
2 return a.*.*;
3}
4pub fn main() void {
5 _ = &entry;
6}
7
8// compile
9// output_mode=Exe
10// backend=selfhosted,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/f_segment_address_space_reading_and_writing.zig created+49
...@@ -0,0 +1,49 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn setFs(value: c_ulong) void {
6 asm volatile (
7 \\syscall
8 :
9 : [number] "{rax}" (158),
10 [code] "{rdi}" (0x1002),
11 [val] "{rsi}" (value),
12 : .{ .rcx = true, .r11 = true, .memory = true }
13 );
14}
15
16fn getFs() c_ulong {
17 var result: c_ulong = undefined;
18 asm volatile (
19 \\syscall
20 :
21 : [number] "{rax}" (158),
22 [code] "{rdi}" (0x1003),
23 [ptr] "{rsi}" (@intFromPtr(&result)),
24 : .{ .rcx = true, .r11 = true, .memory = true }
25 );
26 return result;
27}
28
29var test_value: u64 = 12345;
30
31pub fn main() void {
32 const orig_fs = getFs();
33
34 setFs(@intFromPtr(&test_value));
35 assert(getFs() == @intFromPtr(&test_value));
36
37 var test_ptr: *allowzero addrspace(.fs) u64 = @ptrFromInt(0);
38 _ = &test_ptr;
39 assert(test_ptr.* == 12345);
40 test_ptr.* = 98765;
41 assert(test_value == 98765);
42
43 setFs(orig_fs);
44}
45
46// run
47// backend=llvm
48// target=x86_64-linux
49//
test/cases/for_loop.zig created+16
...@@ -0,0 +1,16 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var x: u32 = 0;
7 for ("hello") |_| {
8 x += 1;
9 }
10 assert("hello".len == x);
11}
12
13// run
14// backend=selfhosted,llvm
15// target=x86_64-linux,x86_64-macos
16//
test/cases/hello_world.zig created+13
...@@ -0,0 +1,13 @@
1extern fn puts(s: [*:0]const u8) c_int;
2
3pub fn main() void {
4 _ = puts("hello world!");
5}
6
7// run
8// backend=selfhosted,llvm
9// target=x86_64-linux,x86_64-macos
10// link_libc=true
11//
12// hello world!
13//
test/cases/large_slices.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 const large_slice = @as([*]const u8, @ptrFromInt(1))[0..(0xffffffffffffffff >> 3)];
3 _ = large_slice;
4}
5
6// compile
7// backend=selfhosted,llvm
8// target=x86_64-linux,x86_64-macos
9//
test/cases/llvm/address_space_pointer_access_chaining_pointer_to_optional_array.zig deleted-12
...@@ -1,12 +0,0 @@
1fn entry(a: *addrspace(.gs) ?[1]i32) *addrspace(.gs) i32 {
2 return &a.*.?[0];
3}
4pub fn main() void {
5 _ = &entry;
6}
7
8// compile
9// output_mode=Exe
10// backend=selfhosted,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/llvm/address_spaces_pointer_access_chaining_array_pointer.zig deleted-12
...@@ -1,12 +0,0 @@
1fn entry(a: *addrspace(.gs) [1]i32) *addrspace(.gs) i32 {
2 return &a[0];
3}
4pub fn main() void {
5 _ = &entry;
6}
7
8// compile
9// output_mode=Exe
10// backend=selfhosted,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/llvm/address_spaces_pointer_access_chaining_complex.zig deleted-13
...@@ -1,13 +0,0 @@
1const A = struct { a: ?[1]i32 };
2fn entry(a: *addrspace(.gs) [1]A) *addrspace(.gs) i32 {
3 return &a[0].a.?[0];
4}
5pub fn main() void {
6 _ = &entry;
7}
8
9// compile
10// output_mode=Exe
11// backend=selfhosted,llvm
12// target=x86_64-linux,x86_64-macos
13//
test/cases/llvm/address_spaces_pointer_access_chaining_struct_pointer.zig deleted-13
...@@ -1,13 +0,0 @@
1const A = struct { a: i32 };
2fn entry(a: *addrspace(.gs) A) *addrspace(.gs) i32 {
3 return &a.a;
4}
5pub fn main() void {
6 _ = &entry;
7}
8
9// compile
10// output_mode=Exe
11// backend=selfhosted,llvm
12// target=x86_64-linux,x86_64-macos
13//
test/cases/llvm/blocks.zig deleted-23
...@@ -1,23 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn foo(ok: bool) i32 {
6 const val: i32 = blk: {
7 var x: i32 = 1;
8 _ = &x;
9 if (!ok) break :blk x + 9;
10 break :blk x + 19;
11 };
12 return val + 10;
13}
14
15pub fn main() void {
16 assert(foo(false) == 20);
17 assert(foo(true) == 30);
18}
19
20// run
21// backend=selfhosted,llvm
22// target=x86_64-linux,x86_64-macos
23//
test/cases/llvm/dereferencing_though_multiple_pointers_with_address_spaces.zig deleted-12
...@@ -1,12 +0,0 @@
1fn entry(a: *addrspace(.fs) *addrspace(.gs) *i32) *i32 {
2 return a.*.*;
3}
4pub fn main() void {
5 _ = &entry;
6}
7
8// compile
9// output_mode=Exe
10// backend=selfhosted,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/llvm/f_segment_address_space_reading_and_writing.zig deleted-49
...@@ -1,49 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn setFs(value: c_ulong) void {
6 asm volatile (
7 \\syscall
8 :
9 : [number] "{rax}" (158),
10 [code] "{rdi}" (0x1002),
11 [val] "{rsi}" (value),
12 : .{ .rcx = true, .r11 = true, .memory = true }
13 );
14}
15
16fn getFs() c_ulong {
17 var result: c_ulong = undefined;
18 asm volatile (
19 \\syscall
20 :
21 : [number] "{rax}" (158),
22 [code] "{rdi}" (0x1003),
23 [ptr] "{rsi}" (@intFromPtr(&result)),
24 : .{ .rcx = true, .r11 = true, .memory = true }
25 );
26 return result;
27}
28
29var test_value: u64 = 12345;
30
31pub fn main() void {
32 const orig_fs = getFs();
33
34 setFs(@intFromPtr(&test_value));
35 assert(getFs() == @intFromPtr(&test_value));
36
37 var test_ptr: *allowzero addrspace(.fs) u64 = @ptrFromInt(0);
38 _ = &test_ptr;
39 assert(test_ptr.* == 12345);
40 test_ptr.* = 98765;
41 assert(test_value == 98765);
42
43 setFs(orig_fs);
44}
45
46// run
47// backend=llvm
48// target=x86_64-linux
49//
test/cases/llvm/for_loop.zig deleted-16
...@@ -1,16 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var x: u32 = 0;
7 for ("hello") |_| {
8 x += 1;
9 }
10 assert("hello".len == x);
11}
12
13// run
14// backend=selfhosted,llvm
15// target=x86_64-linux,x86_64-macos
16//
test/cases/llvm/hello_world.zig deleted-13
...@@ -1,13 +0,0 @@
1extern fn puts(s: [*:0]const u8) c_int;
2
3pub fn main() void {
4 _ = puts("hello world!");
5}
6
7// run
8// backend=selfhosted,llvm
9// target=x86_64-linux,x86_64-macos
10// link_libc=true
11//
12// hello world!
13//
test/cases/llvm/large_slices.zig deleted-9
...@@ -1,9 +0,0 @@
1pub fn main() void {
2 const large_slice = @as([*]const u8, @ptrFromInt(1))[0..(0xffffffffffffffff >> 3)];
3 _ = large_slice;
4}
5
6// compile
7// backend=selfhosted,llvm
8// target=x86_64-linux,x86_64-macos
9//
test/cases/llvm/nested_blocks.zig deleted-24
...@@ -1,24 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn foo(ok: bool) i32 {
6 var val: i32 = blk: {
7 const val2: i32 = another: {
8 if (!ok) break :blk 10;
9 break :another 10;
10 };
11 break :blk val2 + 10;
12 };
13 return (&val).*;
14}
15
16pub fn main() void {
17 assert(foo(false) == 10);
18 assert(foo(true) == 20);
19}
20
21// run
22// backend=selfhosted,llvm
23// target=x86_64-linux,x86_64-macos
24//
test/cases/llvm/optionals.zig deleted-49
...@@ -1,49 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var opt_val: ?i32 = 10;
7 var null_val: ?i32 = null;
8
9 var val1: i32 = opt_val.?;
10 _ = &val1;
11 const val1_1: i32 = opt_val.?;
12 var ptr_val1 = &(opt_val.?);
13 _ = &ptr_val1;
14 const ptr_val1_1 = &(opt_val.?);
15
16 var val2: i32 = null_val orelse 20;
17 const val2_2: i32 = null_val orelse 20;
18
19 var value: i32 = 20;
20 var ptr_val2 = &(null_val orelse value);
21 _ = &ptr_val2;
22
23 const val3 = opt_val orelse 30;
24 var val3_var = opt_val orelse 30;
25 _ = &val3_var;
26
27 assert(val1 == 10);
28 assert(val1_1 == 10);
29 assert(ptr_val1.* == 10);
30 assert(ptr_val1_1.* == 10);
31
32 assert(val2 == 20);
33 assert(val2_2 == 20);
34 assert(ptr_val2.* == 20);
35
36 assert(val3 == 10);
37 assert(val3_var == 10);
38
39 (null_val orelse val2) = 1234;
40 assert(val2 == 1234);
41
42 (opt_val orelse val2) = 5678;
43 assert(opt_val.? == 5678);
44}
45
46// run
47// backend=selfhosted,llvm
48// target=x86_64-linux,x86_64-macos
49//
test/cases/llvm/pointer_keeps_address_space.zig deleted-12
...@@ -1,12 +0,0 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
2 return a;
3}
4pub fn main() void {
5 _ = &entry;
6}
7
8// compile
9// output_mode=Exe
10// backend=selfhosted,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/llvm/pointer_keeps_address_space_when_taking_address_of_dereference.zig deleted-12
...@@ -1,12 +0,0 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
2 return &a.*;
3}
4pub fn main() void {
5 _ = &entry;
6}
7
8// compile
9// output_mode=Exe
10// backend=selfhosted,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/llvm/pointer_to_explicit_generic_address_space_coerces_to_implicit_pointer.zig deleted-12
...@@ -1,12 +0,0 @@
1fn entry(a: *addrspace(.generic) i32) *i32 {
2 return a;
3}
4pub fn main() void {
5 _ = &entry;
6}
7
8// compile
9// output_mode=Exe
10// backend=selfhosted,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/llvm/rem.zig deleted-15
...@@ -1,15 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4fn rem(lhs: i32, rhs: i32, expected: i32) bool {
5 return @rem(lhs, rhs) == expected;
6}
7pub fn main() void {
8 assert(rem(-5, 3, -2));
9 assert(rem(5, 3, 2));
10}
11
12// run
13// backend=selfhosted,llvm
14// target=x86_64-linux,x86_64-macos
15//
test/cases/llvm/simple_addition_and_subtraction.zig deleted-21
...@@ -1,21 +0,0 @@
1fn add(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5pub fn main() void {
6 var a: i32 = -5;
7 _ = &a;
8 const x = add(a, 7);
9 var y = add(2, 0);
10 y -= x;
11 assert(y == 0);
12}
13
14fn assert(ok: bool) void {
15 if (!ok) unreachable;
16}
17
18// run
19// backend=selfhosted,llvm
20// target=x86_64-linux,x86_64-macos
21//
test/cases/llvm/simple_if_statement.zig deleted-16
...@@ -1,16 +0,0 @@
1fn add(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5fn assert(ok: bool) void {
6 if (!ok) unreachable;
7}
8
9pub fn main() void {
10 assert(add(1, 2) == 3);
11}
12
13// run
14// backend=selfhosted,llvm
15// target=x86_64-linux,x86_64-macos
16//
test/cases/llvm/while_loops.zig deleted-18
...@@ -1,18 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var sum: u32 = 0;
7 var i: u32 = 0;
8 while (i < 5) : (i += 1) {
9 sum += i;
10 }
11 assert(sum == 10);
12 assert(i == 5);
13}
14
15// run
16// backend=selfhosted,llvm
17// target=x86_64-linux,x86_64-macos
18//
test/cases/nested_blocks.zig created+24
...@@ -0,0 +1,24 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn foo(ok: bool) i32 {
6 var val: i32 = blk: {
7 const val2: i32 = another: {
8 if (!ok) break :blk 10;
9 break :another 10;
10 };
11 break :blk val2 + 10;
12 };
13 return (&val).*;
14}
15
16pub fn main() void {
17 assert(foo(false) == 10);
18 assert(foo(true) == 20);
19}
20
21// run
22// backend=selfhosted,llvm
23// target=x86_64-linux,x86_64-macos
24//
test/cases/optionals.zig created+49
...@@ -0,0 +1,49 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var opt_val: ?i32 = 10;
7 var null_val: ?i32 = null;
8
9 var val1: i32 = opt_val.?;
10 _ = &val1;
11 const val1_1: i32 = opt_val.?;
12 var ptr_val1 = &(opt_val.?);
13 _ = &ptr_val1;
14 const ptr_val1_1 = &(opt_val.?);
15
16 var val2: i32 = null_val orelse 20;
17 const val2_2: i32 = null_val orelse 20;
18
19 var value: i32 = 20;
20 var ptr_val2 = &(null_val orelse value);
21 _ = &ptr_val2;
22
23 const val3 = opt_val orelse 30;
24 var val3_var = opt_val orelse 30;
25 _ = &val3_var;
26
27 assert(val1 == 10);
28 assert(val1_1 == 10);
29 assert(ptr_val1.* == 10);
30 assert(ptr_val1_1.* == 10);
31
32 assert(val2 == 20);
33 assert(val2_2 == 20);
34 assert(ptr_val2.* == 20);
35
36 assert(val3 == 10);
37 assert(val3_var == 10);
38
39 (null_val orelse val2) = 1234;
40 assert(val2 == 1234);
41
42 (opt_val orelse val2) = 5678;
43 assert(opt_val.? == 5678);
44}
45
46// run
47// backend=selfhosted,llvm
48// target=x86_64-linux,x86_64-macos
49//
test/cases/pointer_keeps_address_space.zig created+12
...@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
2 return a;
3}
4pub fn main() void {
5 _ = &entry;
6}
7
8// compile
9// output_mode=Exe
10// backend=selfhosted,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/pointer_keeps_address_space_when_taking_address_of_dereference.zig created+12
...@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
2 return &a.*;
3}
4pub fn main() void {
5 _ = &entry;
6}
7
8// compile
9// output_mode=Exe
10// backend=selfhosted,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/pointer_to_explicit_generic_address_space_coerces_to_implicit_pointer.zig created+12
...@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.generic) i32) *i32 {
2 return a;
3}
4pub fn main() void {
5 _ = &entry;
6}
7
8// compile
9// output_mode=Exe
10// backend=selfhosted,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/rem.zig created+15
...@@ -0,0 +1,15 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4fn rem(lhs: i32, rhs: i32, expected: i32) bool {
5 return @rem(lhs, rhs) == expected;
6}
7pub fn main() void {
8 assert(rem(-5, 3, -2));
9 assert(rem(5, 3, 2));
10}
11
12// run
13// backend=selfhosted,llvm
14// target=x86_64-linux,x86_64-macos
15//
test/cases/simple_addition_and_subtraction.zig created+21
...@@ -0,0 +1,21 @@
1fn add(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5pub fn main() void {
6 var a: i32 = -5;
7 _ = &a;
8 const x = add(a, 7);
9 var y = add(2, 0);
10 y -= x;
11 assert(y == 0);
12}
13
14fn assert(ok: bool) void {
15 if (!ok) unreachable;
16}
17
18// run
19// backend=selfhosted,llvm
20// target=x86_64-linux,x86_64-macos
21//
test/cases/simple_if_statement.zig created+16
...@@ -0,0 +1,16 @@
1fn add(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5fn assert(ok: bool) void {
6 if (!ok) unreachable;
7}
8
9pub fn main() void {
10 assert(add(1, 2) == 3);
11}
12
13// run
14// backend=selfhosted,llvm
15// target=x86_64-linux,x86_64-macos
16//
test/cases/while_loops.zig created+18
...@@ -0,0 +1,18 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var sum: u32 = 0;
7 var i: u32 = 0;
8 while (i < 5) : (i += 1) {
9 sum += i;
10 }
11 assert(sum == 10);
12 assert(i == 5);
13}
14
15// run
16// backend=selfhosted,llvm
17// target=x86_64-linux,x86_64-macos
18//