authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-28 10:46:05+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-28 18:35:01+02:00
log5a5648c0f03058e1d3878cc8c072af968fc90aa8
tree02d4503f2edcf378c56b8f43004c78a92b8e7b2d
parent2cd456f8f451bc73d719381bcb0f3242a1de2e04

test: migrate llvm incremental tests


28 files changed, 419 insertions(+), 499 deletions(-)

test/cases.zig-2
......@@ -9,8 +9,6 @@ const TestContext = @import("../src/test.zig").TestContext;
99pub fn addCases(ctx: *TestContext) !void {
1010 try @import("compile_errors.zig").addCases(ctx);
1111 try @import("stage2/cbe.zig").addCases(ctx);
12 try @import("stage2/llvm.zig").addCases(ctx);
13 try @import("stage2/x86_64.zig").addCases(ctx);
1412 // https://github.com/ziglang/zig/issues/10968
1513 //try @import("stage2/nvptx.zig").addCases(ctx);
1614}
test/incremental/llvm/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// error
9// output_mode=Exe
10// backend=llvm
11// target=x86_64-linux
12//
test/incremental/llvm/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// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux
12//
test/incremental/llvm/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// error
10// output_mode=Exe
11// backend=llvm
12// target=x86_64-linux
13//
test/incremental/llvm/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// error
10// output_mode=Exe
11// backend=stage2,llvm
12// target=x86_64-linux
13//
test/incremental/llvm/any_typed_null_to_any_typed_optional.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() void {
2 var a: ?*anyopaque = undefined;
3 a = @as(?usize, null);
4}
5
6// error
7// output_mode=Exe
8// backend=stage2,llvm
9// target=x86_64-linux
10//
11// :3:21: error: expected *anyopaque, found ?usize
test/incremental/llvm/blocks.zig created+22
......@@ -0,0 +1,22 @@
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 if (!ok) break :blk x + 9;
9 break :blk x + 19;
10 };
11 return val + 10;
12}
13
14pub fn main() void {
15 assert(foo(false) == 20);
16 assert(foo(true) == 30);
17}
18
19// run
20// backend=stage2,llvm
21// target=x86_64-linux
22//
test/incremental/llvm/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// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux
12//
test/incremental/llvm/f_segment_address_space_reading_and_writing.zig created+48
......@@ -0,0 +1,48 @@
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", "r11", "memory"
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}" (@ptrToInt(&result)),
24 : "rcx", "r11", "memory"
25 );
26 return result;
27}
28
29var test_value: u64 = 12345;
30
31pub fn main() void {
32 const orig_fs = getFs();
33
34 setFs(@ptrToInt(&test_value));
35 assert(getFs() == @ptrToInt(&test_value));
36
37 var test_ptr = @intToPtr(*allowzero addrspace(.fs) u64, 0);
38 assert(test_ptr.* == 12345);
39 test_ptr.* = 98765;
40 assert(test_value == 98765);
41
42 setFs(orig_fs);
43}
44
45// run
46// backend=llvm
47// target=x86_64-linux
48//
test/incremental/llvm/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=stage2,llvm
15// target=x86_64-linux
16//
test/incremental/llvm/hello_world.zig created+12
......@@ -0,0 +1,12 @@
1extern fn puts(s: [*:0]const u8) c_int;
2
3pub fn main() void {
4 _ = puts("hello world!");
5}
6
7// run
8// backend=llvm
9// target=x86_64-linux
10//
11// hello world!
12//
test/incremental/llvm/invalid_address_space_coercion.zig created+13
......@@ -0,0 +1,13 @@
1fn entry(a: *addrspace(.gs) i32) *i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux
12//
13// :2:12: error: expected *i32, found *addrspace(.gs) i32
test/incremental/llvm/invalid_pointer_keeps_address_space_when_taking_address_of_dereference.zig created+13
......@@ -0,0 +1,13 @@
1fn entry(a: *addrspace(.gs) i32) *i32 {
2 return &a.*;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux
12//
13// :2:12: error: expected *i32, found *addrspace(.gs) i32
test/incremental/llvm/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=stage2, llvm
23// target=x86_64-linux
24//
test/incremental/llvm/optionals.zig created+45
......@@ -0,0 +1,45 @@
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 const val1_1: i32 = opt_val.?;
11 var ptr_val1 = &(opt_val.?);
12 const ptr_val1_1 = &(opt_val.?);
13
14 var val2: i32 = null_val orelse 20;
15 const val2_2: i32 = null_val orelse 20;
16
17 var value: i32 = 20;
18 var ptr_val2 = &(null_val orelse value);
19
20 const val3 = opt_val orelse 30;
21 var val3_var = opt_val orelse 30;
22
23 assert(val1 == 10);
24 assert(val1_1 == 10);
25 assert(ptr_val1.* == 10);
26 assert(ptr_val1_1.* == 10);
27
28 assert(val2 == 20);
29 assert(val2_2 == 20);
30 assert(ptr_val2.* == 20);
31
32 assert(val3 == 10);
33 assert(val3_var == 10);
34
35 (null_val orelse val2) = 1234;
36 assert(val2 == 1234);
37
38 (opt_val orelse val2) = 5678;
39 assert(opt_val.? == 5678);
40}
41
42// run
43// backend=llvm
44// target=x86_64-linux
45//
test/incremental/llvm/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// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux
12//
test/incremental/llvm/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// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux
12//
test/incremental/llvm/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// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux
12//
test/incremental/llvm/pointer_with_different_address_spaces.zig created+13
......@@ -0,0 +1,13 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.fs) i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux
12//
13// :2:12: error: expected *addrspace(.fs) i32, found *addrspace(.gs) i32
test/incremental/llvm/pointers_with_different_address_spaces.zig created+13
......@@ -0,0 +1,13 @@
1fn entry(a: ?*addrspace(.gs) i32) *i32 {
2 return a.?;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux
12//
13// :2:13: error: expected *i32, found *addrspace(.gs) i32
test/incremental/llvm/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=stage2,llvm
14// target=x86_64-linux
15//
test/incremental/llvm/shift_right_plus_left.0.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() void {
2 var i: u32 = 16;
3 assert(i >> 1, 8);
4}
5fn assert(a: u32, b: u32) void {
6 if (a != b) unreachable;
7}
8
9// run
10// backend=llvm
11// target=x86_64-linux
12//
test/incremental/llvm/shift_right_plus_left.1.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 var i: u32 = 16;
3 assert(i << 1, 32);
4}
5fn assert(a: u32, b: u32) void {
6 if (a != b) unreachable;
7}
8
9// run
10//
test/incremental/llvm/simple_addition_and_subtraction.zig created+20
......@@ -0,0 +1,20 @@
1fn add(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5pub fn main() void {
6 var a: i32 = -5;
7 const x = add(a, 7);
8 var y = add(2, 0);
9 y -= x;
10 assert(y == 0);
11}
12
13fn assert(ok: bool) void {
14 if (!ok) unreachable;
15}
16
17// run
18// backend=stage2,llvm
19// target=x86_64-linux
20//
test/incremental/llvm/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=stage2,llvm
15// target=x86_64-linux
16//
test/incremental/llvm/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=stage2,llvm
17// target=x86_64-linux
18//
test/stage2/llvm.zig deleted-438
......@@ -1,438 +0,0 @@
1const std = @import("std");
2const TestContext = @import("../../src/test.zig").TestContext;
3const build_options = @import("build_options");
4
5// These tests should work with all platforms, but we're using linux_x64 for
6// now for consistency. Will be expanded eventually.
7const linux_x64 = std.zig.CrossTarget{
8 .cpu_arch = .x86_64,
9 .os_tag = .linux,
10};
11
12pub fn addCases(ctx: *TestContext) !void {
13 {
14 var case = ctx.exeUsingLlvmBackend("simple addition and subtraction", linux_x64);
15
16 case.addCompareOutput(
17 \\fn add(a: i32, b: i32) i32 {
18 \\ return a + b;
19 \\}
20 \\
21 \\pub export fn main() c_int {
22 \\ var a: i32 = -5;
23 \\ const x = add(a, 7);
24 \\ var y = add(2, 0);
25 \\ y -= x;
26 \\ return y;
27 \\}
28 , "");
29 }
30
31 {
32 var case = ctx.exeUsingLlvmBackend("shift right + left", linux_x64);
33
34 case.addCompareOutput(
35 \\pub export fn main() c_int {
36 \\ var i: u32 = 16;
37 \\ assert(i >> 1, 8);
38 \\ return 0;
39 \\}
40 \\fn assert(a: u32, b: u32) void {
41 \\ if (a != b) unreachable;
42 \\}
43 , "");
44 case.addCompareOutput(
45 \\pub export fn main() c_int {
46 \\ var i: u32 = 16;
47 \\ assert(i << 1, 32);
48 \\ return 0;
49 \\}
50 \\fn assert(a: u32, b: u32) void {
51 \\ if (a != b) unreachable;
52 \\}
53 , "");
54 }
55
56 {
57 var case = ctx.exeUsingLlvmBackend("llvm hello world", linux_x64);
58
59 case.addCompareOutput(
60 \\extern fn puts(s: [*:0]const u8) c_int;
61 \\
62 \\pub export fn main() c_int {
63 \\ _ = puts("hello world!");
64 \\ return 0;
65 \\}
66 , "hello world!" ++ std.cstr.line_sep);
67 }
68
69 {
70 var case = ctx.exeUsingLlvmBackend("simple if statement", linux_x64);
71
72 case.addCompareOutput(
73 \\fn add(a: i32, b: i32) i32 {
74 \\ return a + b;
75 \\}
76 \\
77 \\fn assert(ok: bool) void {
78 \\ if (!ok) unreachable;
79 \\}
80 \\
81 \\pub export fn main() c_int {
82 \\ assert(add(1,2) == 3);
83 \\ return 0;
84 \\}
85 , "");
86 }
87
88 {
89 var case = ctx.exeUsingLlvmBackend("blocks", linux_x64);
90
91 case.addCompareOutput(
92 \\fn assert(ok: bool) void {
93 \\ if (!ok) unreachable;
94 \\}
95 \\
96 \\fn foo(ok: bool) i32 {
97 \\ const val: i32 = blk: {
98 \\ var x: i32 = 1;
99 \\ if (!ok) break :blk x + 9;
100 \\ break :blk x + 19;
101 \\ };
102 \\ return val + 10;
103 \\}
104 \\
105 \\pub export fn main() c_int {
106 \\ assert(foo(false) == 20);
107 \\ assert(foo(true) == 30);
108 \\ return 0;
109 \\}
110 , "");
111 }
112
113 {
114 var case = ctx.exeUsingLlvmBackend("nested blocks", linux_x64);
115
116 case.addCompareOutput(
117 \\fn assert(ok: bool) void {
118 \\ if (!ok) unreachable;
119 \\}
120 \\
121 \\fn foo(ok: bool) i32 {
122 \\ var val: i32 = blk: {
123 \\ const val2: i32 = another: {
124 \\ if (!ok) break :blk 10;
125 \\ break :another 10;
126 \\ };
127 \\ break :blk val2 + 10;
128 \\ };
129 \\ return val;
130 \\}
131 \\
132 \\pub export fn main() c_int {
133 \\ assert(foo(false) == 10);
134 \\ assert(foo(true) == 20);
135 \\ return 0;
136 \\}
137 , "");
138 }
139
140 {
141 var case = ctx.exeUsingLlvmBackend("while loops", linux_x64);
142
143 case.addCompareOutput(
144 \\fn assert(ok: bool) void {
145 \\ if (!ok) unreachable;
146 \\}
147 \\
148 \\pub export fn main() c_int {
149 \\ var sum: u32 = 0;
150 \\ var i: u32 = 0;
151 \\ while (i < 5) : (i += 1) {
152 \\ sum += i;
153 \\ }
154 \\ assert(sum == 10);
155 \\ assert(i == 5);
156 \\ return 0;
157 \\}
158 , "");
159 }
160
161 {
162 var case = ctx.exeUsingLlvmBackend("optionals", linux_x64);
163
164 case.addCompareOutput(
165 \\fn assert(ok: bool) void {
166 \\ if (!ok) unreachable;
167 \\}
168 \\
169 \\pub export fn main() c_int {
170 \\ var opt_val: ?i32 = 10;
171 \\ var null_val: ?i32 = null;
172 \\
173 \\ var val1: i32 = opt_val.?;
174 \\ const val1_1: i32 = opt_val.?;
175 \\ var ptr_val1 = &(opt_val.?);
176 \\ const ptr_val1_1 = &(opt_val.?);
177 \\
178 \\ var val2: i32 = null_val orelse 20;
179 \\ const val2_2: i32 = null_val orelse 20;
180 \\
181 \\ var value: i32 = 20;
182 \\ var ptr_val2 = &(null_val orelse value);
183 \\
184 \\ const val3 = opt_val orelse 30;
185 \\ var val3_var = opt_val orelse 30;
186 \\
187 \\ assert(val1 == 10);
188 \\ assert(val1_1 == 10);
189 \\ assert(ptr_val1.* == 10);
190 \\ assert(ptr_val1_1.* == 10);
191 \\
192 \\ assert(val2 == 20);
193 \\ assert(val2_2 == 20);
194 \\ assert(ptr_val2.* == 20);
195 \\
196 \\ assert(val3 == 10);
197 \\ assert(val3_var == 10);
198 \\
199 \\ (null_val orelse val2) = 1234;
200 \\ assert(val2 == 1234);
201 \\
202 \\ (opt_val orelse val2) = 5678;
203 \\ assert(opt_val.? == 5678);
204 \\
205 \\ return 0;
206 \\}
207 , "");
208 }
209
210 {
211 var case = ctx.exeUsingLlvmBackend("for loop", linux_x64);
212
213 case.addCompareOutput(
214 \\fn assert(ok: bool) void {
215 \\ if (!ok) unreachable;
216 \\}
217 \\
218 \\pub export fn main() c_int {
219 \\ var x: u32 = 0;
220 \\ for ("hello") |_| {
221 \\ x += 1;
222 \\ }
223 \\ assert("hello".len == x);
224 \\ return 0;
225 \\}
226 , "");
227 }
228
229 {
230 var case = ctx.exeUsingLlvmBackend("@rem", linux_x64);
231 case.addCompareOutput(
232 \\fn assert(ok: bool) void {
233 \\ if (!ok) unreachable;
234 \\}
235 \\fn rem(lhs: i32, rhs: i32, expected: i32) bool {
236 \\ return @rem(lhs, rhs) == expected;
237 \\}
238 \\pub export fn main() c_int {
239 \\ assert(rem(-5, 3, -2));
240 \\ assert(rem(5, 3, 2));
241 \\ return 0;
242 \\}
243 , "");
244 }
245
246 {
247 var case = ctx.exeUsingLlvmBackend("invalid address space coercion", linux_x64);
248 case.addError(
249 \\fn entry(a: *addrspace(.gs) i32) *i32 {
250 \\ return a;
251 \\}
252 \\pub export fn main() void { _ = entry; }
253 , &[_][]const u8{
254 ":2:12: error: expected *i32, found *addrspace(.gs) i32",
255 });
256 }
257
258 {
259 var case = ctx.exeUsingLlvmBackend("pointer keeps address space", linux_x64);
260 case.compiles(
261 \\fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
262 \\ return a;
263 \\}
264 \\pub export fn main() void { _ = entry; }
265 );
266 }
267
268 {
269 var case = ctx.exeUsingLlvmBackend("pointer to explicit generic address space coerces to implicit pointer", linux_x64);
270 case.compiles(
271 \\fn entry(a: *addrspace(.generic) i32) *i32 {
272 \\ return a;
273 \\}
274 \\pub export fn main() void { _ = entry; }
275 );
276 }
277
278 {
279 var case = ctx.exeUsingLlvmBackend("pointers with different address spaces", linux_x64);
280 case.addError(
281 \\fn entry(a: *addrspace(.gs) i32) *addrspace(.fs) i32 {
282 \\ return a;
283 \\}
284 \\pub export fn main() void { _ = entry; }
285 , &[_][]const u8{
286 ":2:12: error: expected *addrspace(.fs) i32, found *addrspace(.gs) i32",
287 });
288 }
289
290 {
291 var case = ctx.exeUsingLlvmBackend("pointers with different address spaces", linux_x64);
292 case.addError(
293 \\fn entry(a: ?*addrspace(.gs) i32) *i32 {
294 \\ return a.?;
295 \\}
296 \\pub export fn main() void { _ = entry; }
297 , &[_][]const u8{
298 ":2:13: error: expected *i32, found *addrspace(.gs) i32",
299 });
300 }
301
302 {
303 var case = ctx.exeUsingLlvmBackend("invalid pointer keeps address space when taking address of dereference", linux_x64);
304 case.addError(
305 \\fn entry(a: *addrspace(.gs) i32) *i32 {
306 \\ return &a.*;
307 \\}
308 \\pub export fn main() void { _ = entry; }
309 , &[_][]const u8{
310 ":2:12: error: expected *i32, found *addrspace(.gs) i32",
311 });
312 }
313
314 {
315 var case = ctx.exeUsingLlvmBackend("pointer keeps address space when taking address of dereference", linux_x64);
316 case.compiles(
317 \\fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
318 \\ return &a.*;
319 \\}
320 \\pub export fn main() void { _ = entry; }
321 );
322 }
323
324 {
325 var case = ctx.exeUsingLlvmBackend("address spaces pointer access chaining: array pointer", linux_x64);
326 case.compiles(
327 \\fn entry(a: *addrspace(.gs) [1]i32) *addrspace(.gs) i32 {
328 \\ return &a[0];
329 \\}
330 \\pub export fn main() void { _ = entry; }
331 );
332 }
333
334 {
335 var case = ctx.exeUsingLlvmBackend("address spaces pointer access chaining: pointer to optional array", linux_x64);
336 case.compiles(
337 \\fn entry(a: *addrspace(.gs) ?[1]i32) *addrspace(.gs) i32 {
338 \\ return &a.*.?[0];
339 \\}
340 \\pub export fn main() void { _ = entry; }
341 );
342 }
343
344 {
345 var case = ctx.exeUsingLlvmBackend("address spaces pointer access chaining: struct pointer", linux_x64);
346 case.compiles(
347 \\const A = struct{ a: i32 };
348 \\fn entry(a: *addrspace(.gs) A) *addrspace(.gs) i32 {
349 \\ return &a.a;
350 \\}
351 \\pub export fn main() void { _ = entry; }
352 );
353 }
354
355 {
356 var case = ctx.exeUsingLlvmBackend("address spaces pointer access chaining: complex", linux_x64);
357 case.compiles(
358 \\const A = struct{ a: ?[1]i32 };
359 \\fn entry(a: *addrspace(.gs) [1]A) *addrspace(.gs) i32 {
360 \\ return &a[0].a.?[0];
361 \\}
362 \\pub export fn main() void { _ = entry; }
363 );
364 }
365
366 {
367 var case = ctx.exeUsingLlvmBackend("dereferencing through multiple pointers with address spaces", linux_x64);
368 case.compiles(
369 \\fn entry(a: *addrspace(.fs) *addrspace(.gs) *i32) *i32 {
370 \\ return a.*.*;
371 \\}
372 \\pub export fn main() void { _ = entry; }
373 );
374 }
375
376 {
377 var case = ctx.exeUsingLlvmBackend("f segment address space reading and writing", linux_x64);
378 case.addCompareOutput(
379 \\fn assert(ok: bool) void {
380 \\ if (!ok) unreachable;
381 \\}
382 \\
383 \\fn setFs(value: c_ulong) void {
384 \\ asm volatile (
385 \\ \\syscall
386 \\ :
387 \\ : [number] "{rax}" (158),
388 \\ [code] "{rdi}" (0x1002),
389 \\ [val] "{rsi}" (value),
390 \\ : "rcx", "r11", "memory"
391 \\ );
392 \\}
393 \\
394 \\fn getFs() c_ulong {
395 \\ var result: c_ulong = undefined;
396 \\ asm volatile (
397 \\ \\syscall
398 \\ :
399 \\ : [number] "{rax}" (158),
400 \\ [code] "{rdi}" (0x1003),
401 \\ [ptr] "{rsi}" (@ptrToInt(&result)),
402 \\ : "rcx", "r11", "memory"
403 \\ );
404 \\ return result;
405 \\}
406 \\
407 \\var test_value: u64 = 12345;
408 \\
409 \\pub export fn main() c_int {
410 \\ const orig_fs = getFs();
411 \\
412 \\ setFs(@ptrToInt(&test_value));
413 \\ assert(getFs() == @ptrToInt(&test_value));
414 \\
415 \\ var test_ptr = @intToPtr(*allowzero addrspace(.fs) u64, 0);
416 \\ assert(test_ptr.* == 12345);
417 \\ test_ptr.* = 98765;
418 \\ assert(test_value == 98765);
419 \\
420 \\ setFs(orig_fs);
421 \\ return 0;
422 \\}
423 , "");
424 }
425
426 {
427 // This worked in stage1 and we expressly do not want this to work in stage2
428 var case = ctx.exeUsingLlvmBackend("any typed null to any typed optional", linux_x64);
429 case.addError(
430 \\pub export fn main() void {
431 \\ var a: ?*anyopaque = undefined;
432 \\ a = @as(?usize, null);
433 \\}
434 , &[_][]const u8{
435 ":3:21: error: expected *anyopaque, found ?usize",
436 });
437 }
438}
test/stage2/x86_64.zig deleted-59
......@@ -1,59 +0,0 @@
1const std = @import("std");
2const CrossTarget = std.zig.CrossTarget;
3const TestContext = @import("../../src/test.zig").TestContext;
4
5const linux_x64 = std.zig.CrossTarget{
6 .cpu_arch = .x86_64,
7 .os_tag = .linux,
8};
9const macos_x64 = CrossTarget{
10 .cpu_arch = .x86_64,
11 .os_tag = .macos,
12};
13const all_targets: []const CrossTarget = &[_]CrossTarget{
14 linux_x64,
15 macos_x64,
16};
17
18pub fn addCases(ctx: *TestContext) !void {
19 for (all_targets) |target| {
20 // TODO port this to the new test harness
21 var case = ctx.exe("basic import", target);
22 case.addCompareOutput(
23 \\pub fn main() void {
24 \\ @import("print.zig").print();
25 \\}
26 ,
27 "Hello, World!\n",
28 );
29 switch (target.getOsTag()) {
30 .linux => try case.files.append(.{
31 .src =
32 \\pub fn print() void {
33 \\ asm volatile ("syscall"
34 \\ :
35 \\ : [number] "{rax}" (@as(usize, 1)),
36 \\ [arg1] "{rdi}" (@as(usize, 1)),
37 \\ [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
38 \\ [arg3] "{rdx}" (@as(usize, 14))
39 \\ : "rcx", "r11", "memory"
40 \\ );
41 \\ return;
42 \\}
43 ,
44 .path = "print.zig",
45 }),
46 .macos => try case.files.append(.{
47 .src =
48 \\extern "c" fn write(usize, usize, usize) usize;
49 \\
50 \\pub fn print() void {
51 \\ _ = write(1, @ptrToInt("Hello, World!\n"), 14);
52 \\}
53 ,
54 .path = "print.zig",
55 }),
56 else => unreachable,
57 }
58 }
59}