authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-17 14:39:56-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-17 16:09:20-07:00
log8a7a07f30dc9aedb596db327f57d5dc12f2ffd52
tree365b7090109244daa620afd42820ee62da2b2d03
parent83677074f95930d0fcb95a4eed276637d52afde7

stage2: test cases take advantage of `pub fn main` support


3 files changed, 62 insertions(+), 602 deletions(-)

BRANCH_TODO-2
...@@ -1,5 +1,3 @@...@@ -1,5 +1,3 @@
1 * modify stage2 tests so that only 1 uses _start and the rest use
2 pub fn main
3 * modify stage2 CBE tests so that only 1 uses pub export main and the1 * modify stage2 CBE tests so that only 1 uses pub export main and the
4 rest use pub fn main2 rest use pub fn main
53
test/stage2/arm.zig+14-157
...@@ -9,7 +9,7 @@ const linux_arm = std.zig.CrossTarget{...@@ -9,7 +9,7 @@ const linux_arm = std.zig.CrossTarget{
9pub fn addCases(ctx: *TestContext) !void {9pub fn addCases(ctx: *TestContext) !void {
10 {10 {
11 var case = ctx.exe("linux_arm hello world", linux_arm);11 var case = ctx.exe("linux_arm hello world", linux_arm);
12 // Regular old hello world12 // Hello world using _start and inline asm.
13 case.addCompareOutput(13 case.addCompareOutput(
14 \\pub export fn _start() noreturn {14 \\pub export fn _start() noreturn {
15 \\ print();15 \\ print();
...@@ -50,9 +50,8 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -50,9 +50,8 @@ pub fn addCases(ctx: *TestContext) !void {
50 // be in a specific order because otherwise the write to r050 // be in a specific order because otherwise the write to r0
51 // would overwrite the len parameter which resides in r051 // would overwrite the len parameter which resides in r0
52 case.addCompareOutput(52 case.addCompareOutput(
53 \\pub export fn _start() noreturn {53 \\pub fn main() void {
54 \\ print(id(14));54 \\ print(id(14));
55 \\ exit();
56 \\}55 \\}
57 \\56 \\
58 \\fn id(x: u32) u32 {57 \\fn id(x: u32) u32 {
...@@ -70,16 +69,6 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -70,16 +69,6 @@ pub fn addCases(ctx: *TestContext) !void {
70 \\ );69 \\ );
71 \\ return;70 \\ return;
72 \\}71 \\}
73 \\
74 \\fn exit() noreturn {
75 \\ asm volatile ("svc #0"
76 \\ :
77 \\ : [number] "{r7}" (1),
78 \\ [arg1] "{r0}" (0)
79 \\ : "memory"
80 \\ );
81 \\ unreachable;
82 \\}
83 ,72 ,
84 "Hello, World!\n",73 "Hello, World!\n",
85 );74 );
...@@ -89,9 +78,8 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -89,9 +78,8 @@ pub fn addCases(ctx: *TestContext) !void {
89 var case = ctx.exe("non-leaf functions", linux_arm);78 var case = ctx.exe("non-leaf functions", linux_arm);
90 // Testing non-leaf functions79 // Testing non-leaf functions
91 case.addCompareOutput(80 case.addCompareOutput(
92 \\pub export fn _start() noreturn {81 \\pub fn main() void {
93 \\ foo();82 \\ foo();
94 \\ exit();
95 \\}83 \\}
96 \\84 \\
97 \\fn foo() void {85 \\fn foo() void {
...@@ -99,16 +87,6 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -99,16 +87,6 @@ pub fn addCases(ctx: *TestContext) !void {
99 \\}87 \\}
100 \\88 \\
101 \\fn bar() void {}89 \\fn bar() void {}
102 \\
103 \\fn exit() noreturn {
104 \\ asm volatile ("svc #0"
105 \\ :
106 \\ : [number] "{r7}" (1),
107 \\ [arg1] "{r0}" (0)
108 \\ : "memory"
109 \\ );
110 \\ unreachable;
111 \\}
112 ,90 ,
113 "",91 "",
114 );92 );
...@@ -119,10 +97,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -119,10 +97,9 @@ pub fn addCases(ctx: *TestContext) !void {
11997
120 // Add two numbers98 // Add two numbers
121 case.addCompareOutput(99 case.addCompareOutput(
122 \\pub export fn _start() noreturn {100 \\pub fn main() void {
123 \\ print(2, 4);101 \\ print(2, 4);
124 \\ print(1, 7);102 \\ print(1, 7);
125 \\ exit();
126 \\}103 \\}
127 \\104 \\
128 \\fn print(a: u32, b: u32) void {105 \\fn print(a: u32, b: u32) void {
...@@ -136,26 +113,15 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -136,26 +113,15 @@ pub fn addCases(ctx: *TestContext) !void {
136 \\ );113 \\ );
137 \\ return;114 \\ return;
138 \\}115 \\}
139 \\
140 \\fn exit() noreturn {
141 \\ asm volatile ("svc #0"
142 \\ :
143 \\ : [number] "{r7}" (1),
144 \\ [arg1] "{r0}" (0)
145 \\ : "memory"
146 \\ );
147 \\ unreachable;
148 \\}
149 ,116 ,
150 "12345612345678",117 "12345612345678",
151 );118 );
152119
153 // Subtract two numbers120 // Subtract two numbers
154 case.addCompareOutput(121 case.addCompareOutput(
155 \\pub export fn _start() noreturn {122 \\pub fn main() void {
156 \\ print(10, 5);123 \\ print(10, 5);
157 \\ print(4, 3);124 \\ print(4, 3);
158 \\ exit();
159 \\}125 \\}
160 \\126 \\
161 \\fn print(a: u32, b: u32) void {127 \\fn print(a: u32, b: u32) void {
...@@ -169,26 +135,15 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -169,26 +135,15 @@ pub fn addCases(ctx: *TestContext) !void {
169 \\ );135 \\ );
170 \\ return;136 \\ return;
171 \\}137 \\}
172 \\
173 \\fn exit() noreturn {
174 \\ asm volatile ("svc #0"
175 \\ :
176 \\ : [number] "{r7}" (1),
177 \\ [arg1] "{r0}" (0)
178 \\ : "memory"
179 \\ );
180 \\ unreachable;
181 \\}
182 ,138 ,
183 "123451",139 "123451",
184 );140 );
185141
186 // Bitwise And142 // Bitwise And
187 case.addCompareOutput(143 case.addCompareOutput(
188 \\pub export fn _start() noreturn {144 \\pub fn main() void {
189 \\ print(8, 9);145 \\ print(8, 9);
190 \\ print(3, 7);146 \\ print(3, 7);
191 \\ exit();
192 \\}147 \\}
193 \\148 \\
194 \\fn print(a: u32, b: u32) void {149 \\fn print(a: u32, b: u32) void {
...@@ -202,26 +157,15 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -202,26 +157,15 @@ pub fn addCases(ctx: *TestContext) !void {
202 \\ );157 \\ );
203 \\ return;158 \\ return;
204 \\}159 \\}
205 \\
206 \\fn exit() noreturn {
207 \\ asm volatile ("svc #0"
208 \\ :
209 \\ : [number] "{r7}" (1),
210 \\ [arg1] "{r0}" (0)
211 \\ : "memory"
212 \\ );
213 \\ unreachable;
214 \\}
215 ,160 ,
216 "12345678123",161 "12345678123",
217 );162 );
218163
219 // Bitwise Or164 // Bitwise Or
220 case.addCompareOutput(165 case.addCompareOutput(
221 \\pub export fn _start() noreturn {166 \\pub fn main() void {
222 \\ print(4, 2);167 \\ print(4, 2);
223 \\ print(3, 7);168 \\ print(3, 7);
224 \\ exit();
225 \\}169 \\}
226 \\170 \\
227 \\fn print(a: u32, b: u32) void {171 \\fn print(a: u32, b: u32) void {
...@@ -235,26 +179,15 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -235,26 +179,15 @@ pub fn addCases(ctx: *TestContext) !void {
235 \\ );179 \\ );
236 \\ return;180 \\ return;
237 \\}181 \\}
238 \\
239 \\fn exit() noreturn {
240 \\ asm volatile ("svc #0"
241 \\ :
242 \\ : [number] "{r7}" (1),
243 \\ [arg1] "{r0}" (0)
244 \\ : "memory"
245 \\ );
246 \\ unreachable;
247 \\}
248 ,182 ,
249 "1234561234567",183 "1234561234567",
250 );184 );
251185
252 // Bitwise Xor186 // Bitwise Xor
253 case.addCompareOutput(187 case.addCompareOutput(
254 \\pub export fn _start() noreturn {188 \\pub fn main() void {
255 \\ print(42, 42);189 \\ print(42, 42);
256 \\ print(3, 5);190 \\ print(3, 5);
257 \\ exit();
258 \\}191 \\}
259 \\192 \\
260 \\fn print(a: u32, b: u32) void {193 \\fn print(a: u32, b: u32) void {
...@@ -268,16 +201,6 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -268,16 +201,6 @@ pub fn addCases(ctx: *TestContext) !void {
268 \\ );201 \\ );
269 \\ return;202 \\ return;
270 \\}203 \\}
271 \\
272 \\fn exit() noreturn {
273 \\ asm volatile ("svc #0"
274 \\ :
275 \\ : [number] "{r7}" (1),
276 \\ [arg1] "{r0}" (0)
277 \\ : "memory"
278 \\ );
279 \\ unreachable;
280 \\}
281 ,204 ,
282 "123456",205 "123456",
283 );206 );
...@@ -287,26 +210,15 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -287,26 +210,15 @@ pub fn addCases(ctx: *TestContext) !void {
287 var case = ctx.exe("if statements", linux_arm);210 var case = ctx.exe("if statements", linux_arm);
288 // Simple if statement in assert211 // Simple if statement in assert
289 case.addCompareOutput(212 case.addCompareOutput(
290 \\pub export fn _start() noreturn {213 \\pub fn main() void {
291 \\ var x: u32 = 123;214 \\ var x: u32 = 123;
292 \\ var y: u32 = 42;215 \\ var y: u32 = 42;
293 \\ assert(x > y);216 \\ assert(x > y);
294 \\ exit();
295 \\}217 \\}
296 \\218 \\
297 \\fn assert(ok: bool) void {219 \\fn assert(ok: bool) void {
298 \\ if (!ok) unreachable;220 \\ if (!ok) unreachable;
299 \\}221 \\}
300 \\
301 \\fn exit() noreturn {
302 \\ asm volatile ("svc #0"
303 \\ :
304 \\ : [number] "{r7}" (1),
305 \\ [arg1] "{r0}" (0)
306 \\ : "memory"
307 \\ );
308 \\ unreachable;
309 \\}
310 ,222 ,
311 "",223 "",
312 );224 );
...@@ -316,7 +228,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -316,7 +228,7 @@ pub fn addCases(ctx: *TestContext) !void {
316 var case = ctx.exe("while loops", linux_arm);228 var case = ctx.exe("while loops", linux_arm);
317 // Simple while loop with assert229 // Simple while loop with assert
318 case.addCompareOutput(230 case.addCompareOutput(
319 \\pub export fn _start() noreturn {231 \\pub fn main() void {
320 \\ var x: u32 = 2020;232 \\ var x: u32 = 2020;
321 \\ var i: u32 = 0;233 \\ var i: u32 = 0;
322 \\ while (x > 0) {234 \\ while (x > 0) {
...@@ -324,22 +236,11 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -324,22 +236,11 @@ pub fn addCases(ctx: *TestContext) !void {
324 \\ i += 1;236 \\ i += 1;
325 \\ }237 \\ }
326 \\ assert(i == 1010);238 \\ assert(i == 1010);
327 \\ exit();
328 \\}239 \\}
329 \\240 \\
330 \\fn assert(ok: bool) void {241 \\fn assert(ok: bool) void {
331 \\ if (!ok) unreachable;242 \\ if (!ok) unreachable;
332 \\}243 \\}
333 \\
334 \\fn exit() noreturn {
335 \\ asm volatile ("svc #0"
336 \\ :
337 \\ : [number] "{r7}" (1),
338 \\ [arg1] "{r0}" (0)
339 \\ : "memory"
340 \\ );
341 \\ unreachable;
342 \\}
343 ,244 ,
344 "",245 "",
345 );246 );
...@@ -349,12 +250,11 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -349,12 +250,11 @@ pub fn addCases(ctx: *TestContext) !void {
349 var case = ctx.exe("integer multiplication", linux_arm);250 var case = ctx.exe("integer multiplication", linux_arm);
350 // Simple u32 integer multiplication251 // Simple u32 integer multiplication
351 case.addCompareOutput(252 case.addCompareOutput(
352 \\pub export fn _start() noreturn {253 \\pub fn main() void {
353 \\ assert(mul(1, 1) == 1);254 \\ assert(mul(1, 1) == 1);
354 \\ assert(mul(42, 1) == 42);255 \\ assert(mul(42, 1) == 42);
355 \\ assert(mul(1, 42) == 42);256 \\ assert(mul(1, 42) == 42);
356 \\ assert(mul(123, 42) == 5166);257 \\ assert(mul(123, 42) == 5166);
357 \\ exit();
358 \\}258 \\}
359 \\259 \\
360 \\fn mul(x: u32, y: u32) u32 {260 \\fn mul(x: u32, y: u32) u32 {
...@@ -364,16 +264,6 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -364,16 +264,6 @@ pub fn addCases(ctx: *TestContext) !void {
364 \\fn assert(ok: bool) void {264 \\fn assert(ok: bool) void {
365 \\ if (!ok) unreachable;265 \\ if (!ok) unreachable;
366 \\}266 \\}
367 \\
368 \\fn exit() noreturn {
369 \\ asm volatile ("svc #0"
370 \\ :
371 \\ : [number] "{r7}" (1),
372 \\ [arg1] "{r0}" (0)
373 \\ : "memory"
374 \\ );
375 \\ unreachable;
376 \\}
377 ,267 ,
378 "",268 "",
379 );269 );
...@@ -385,9 +275,8 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -385,9 +275,8 @@ pub fn addCases(ctx: *TestContext) !void {
385 // callee preserved register, otherwise it will be overwritten275 // callee preserved register, otherwise it will be overwritten
386 // by the first parameter to baz.276 // by the first parameter to baz.
387 case.addCompareOutput(277 case.addCompareOutput(
388 \\pub export fn _start() noreturn {278 \\pub fn main() void {
389 \\ assert(foo() == 43);279 \\ assert(foo() == 43);
390 \\ exit();
391 \\}280 \\}
392 \\281 \\
393 \\fn foo() u32 {282 \\fn foo() u32 {
...@@ -405,16 +294,6 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -405,16 +294,6 @@ pub fn addCases(ctx: *TestContext) !void {
405 \\fn assert(ok: bool) void {294 \\fn assert(ok: bool) void {
406 \\ if (!ok) unreachable;295 \\ if (!ok) unreachable;
407 \\}296 \\}
408 \\
409 \\fn exit() noreturn {
410 \\ asm volatile ("svc #0"
411 \\ :
412 \\ : [number] "{r7}" (1),
413 \\ [arg1] "{r0}" (0)
414 \\ : "memory"
415 \\ );
416 \\ unreachable;
417 \\}
418 ,297 ,
419 "",298 "",
420 );299 );
...@@ -423,14 +302,13 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -423,14 +302,13 @@ pub fn addCases(ctx: *TestContext) !void {
423 {302 {
424 var case = ctx.exe("recursive fibonacci", linux_arm);303 var case = ctx.exe("recursive fibonacci", linux_arm);
425 case.addCompareOutput(304 case.addCompareOutput(
426 \\pub export fn _start() noreturn {305 \\pub fn main() void {
427 \\ assert(fib(0) == 0);306 \\ assert(fib(0) == 0);
428 \\ assert(fib(1) == 1);307 \\ assert(fib(1) == 1);
429 \\ assert(fib(2) == 1);308 \\ assert(fib(2) == 1);
430 \\ assert(fib(3) == 2);309 \\ assert(fib(3) == 2);
431 \\ assert(fib(10) == 55);310 \\ assert(fib(10) == 55);
432 \\ assert(fib(20) == 6765);311 \\ assert(fib(20) == 6765);
433 \\ exit();
434 \\}312 \\}
435 \\313 \\
436 \\fn fib(n: u32) u32 {314 \\fn fib(n: u32) u32 {
...@@ -444,16 +322,6 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -444,16 +322,6 @@ pub fn addCases(ctx: *TestContext) !void {
444 \\fn assert(ok: bool) void {322 \\fn assert(ok: bool) void {
445 \\ if (!ok) unreachable;323 \\ if (!ok) unreachable;
446 \\}324 \\}
447 \\
448 \\fn exit() noreturn {
449 \\ asm volatile ("svc #0"
450 \\ :
451 \\ : [number] "{r7}" (1),
452 \\ [arg1] "{r0}" (0)
453 \\ : "memory"
454 \\ );
455 \\ unreachable;
456 \\}
457 ,325 ,
458 "",326 "",
459 );327 );
...@@ -462,9 +330,8 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -462,9 +330,8 @@ pub fn addCases(ctx: *TestContext) !void {
462 {330 {
463 var case = ctx.exe("spilling registers", linux_arm);331 var case = ctx.exe("spilling registers", linux_arm);
464 case.addCompareOutput(332 case.addCompareOutput(
465 \\pub export fn _start() noreturn {333 \\pub fn main() void {
466 \\ assert(add(3, 4) == 791);334 \\ assert(add(3, 4) == 791);
467 \\ exit();
468 \\}335 \\}
469 \\336 \\
470 \\fn add(a: u32, b: u32) u32 {337 \\fn add(a: u32, b: u32) u32 {
...@@ -497,16 +364,6 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -497,16 +364,6 @@ pub fn addCases(ctx: *TestContext) !void {
497 \\fn assert(ok: bool) void {364 \\fn assert(ok: bool) void {
498 \\ if (!ok) unreachable;365 \\ if (!ok) unreachable;
499 \\}366 \\}
500 \\
501 \\fn exit() noreturn {
502 \\ asm volatile ("svc #0"
503 \\ :
504 \\ : [number] "{r7}" (1),
505 \\ [arg1] "{r0}" (0)
506 \\ : "memory"
507 \\ );
508 \\ unreachable;
509 \\}
510 ,367 ,
511 "",368 "",
512 );369 );
test/stage2/test.zig+48-443
...@@ -65,6 +65,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -65,6 +65,7 @@ pub fn addCases(ctx: *TestContext) !void {
65 ,65 ,
66 "Hello, World!\n",66 "Hello, World!\n",
67 );67 );
68
68 // Now change the message only69 // Now change the message only
69 case.addCompareOutput(70 case.addCompareOutput(
70 \\pub export fn _start() noreturn {71 \\pub export fn _start() noreturn {
...@@ -237,25 +238,13 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -237,25 +238,13 @@ pub fn addCases(ctx: *TestContext) !void {
237 {238 {
238 var case = ctx.exe("subtracting numbers at runtime", linux_x64);239 var case = ctx.exe("subtracting numbers at runtime", linux_x64);
239 case.addCompareOutput(240 case.addCompareOutput(
240 \\pub export fn _start() noreturn {241 \\pub fn main() void {
241 \\ sub(7, 4);242 \\ sub(7, 4);
242 \\
243 \\ exit();
244 \\}243 \\}
245 \\244 \\
246 \\fn sub(a: u32, b: u32) void {245 \\fn sub(a: u32, b: u32) void {
247 \\ if (a - b != 3) unreachable;246 \\ if (a - b != 3) unreachable;
248 \\}247 \\}
249 \\
250 \\fn exit() noreturn {
251 \\ asm volatile ("syscall"
252 \\ :
253 \\ : [number] "{rax}" (231),
254 \\ [arg1] "{rdi}" (0)
255 \\ : "rcx", "r11", "memory"
256 \\ );
257 \\ unreachable;
258 \\}
259 ,248 ,
260 "",249 "",
261 );250 );
...@@ -263,58 +252,33 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -263,58 +252,33 @@ pub fn addCases(ctx: *TestContext) !void {
263 {252 {
264 var case = ctx.exe("@TypeOf", linux_x64);253 var case = ctx.exe("@TypeOf", linux_x64);
265 case.addCompareOutput(254 case.addCompareOutput(
266 \\pub export fn _start() noreturn {255 \\pub fn main() void {
267 \\ var x: usize = 0;256 \\ var x: usize = 0;
268 \\ const z = @TypeOf(x, @as(u128, 5));257 \\ const z = @TypeOf(x, @as(u128, 5));
269 \\ assert(z == u128);258 \\ assert(z == u128);
270 \\
271 \\ exit();
272 \\}259 \\}
273 \\260 \\
274 \\pub fn assert(ok: bool) void {261 \\pub fn assert(ok: bool) void {
275 \\ if (!ok) unreachable; // assertion failure262 \\ if (!ok) unreachable; // assertion failure
276 \\}263 \\}
277 \\
278 \\fn exit() noreturn {
279 \\ asm volatile ("syscall"
280 \\ :
281 \\ : [number] "{rax}" (231),
282 \\ [arg1] "{rdi}" (0)
283 \\ : "rcx", "r11", "memory"
284 \\ );
285 \\ unreachable;
286 \\}
287 ,264 ,
288 "",265 "",
289 );266 );
290 case.addCompareOutput(267 case.addCompareOutput(
291 \\pub export fn _start() noreturn {268 \\pub fn main() void {
292 \\ const z = @TypeOf(true);269 \\ const z = @TypeOf(true);
293 \\ assert(z == bool);270 \\ assert(z == bool);
294 \\
295 \\ exit();
296 \\}271 \\}
297 \\272 \\
298 \\pub fn assert(ok: bool) void {273 \\pub fn assert(ok: bool) void {
299 \\ if (!ok) unreachable; // assertion failure274 \\ if (!ok) unreachable; // assertion failure
300 \\}275 \\}
301 \\
302 \\fn exit() noreturn {
303 \\ asm volatile ("syscall"
304 \\ :
305 \\ : [number] "{rax}" (231),
306 \\ [arg1] "{rdi}" (0)
307 \\ : "rcx", "r11", "memory"
308 \\ );
309 \\ unreachable;
310 \\}
311 ,276 ,
312 "",277 "",
313 );278 );
314 case.addError(279 case.addError(
315 \\pub export fn _start() noreturn {280 \\pub fn main() void {
316 \\ const z = @TypeOf(true, 1);281 \\ const z = @TypeOf(true, 1);
317 \\ unreachable;
318 \\}282 \\}
319 , &[_][]const u8{":2:15: error: incompatible types: 'bool' and 'comptime_int'"});283 , &[_][]const u8{":2:15: error: incompatible types: 'bool' and 'comptime_int'"});
320 }284 }
...@@ -346,7 +310,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -346,7 +310,7 @@ pub fn addCases(ctx: *TestContext) !void {
346 );310 );
347 // comptime function call311 // comptime function call
348 case.addCompareOutput(312 case.addCompareOutput(
349 \\pub export fn _start() noreturn {313 \\pub fn _start() noreturn {
350 \\ exit();314 \\ exit();
351 \\}315 \\}
352 \\316 \\
...@@ -397,10 +361,8 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -397,10 +361,8 @@ pub fn addCases(ctx: *TestContext) !void {
397 {361 {
398 var case = ctx.exe("assert function", linux_x64);362 var case = ctx.exe("assert function", linux_x64);
399 case.addCompareOutput(363 case.addCompareOutput(
400 \\pub export fn _start() noreturn {364 \\pub fn main() void {
401 \\ add(3, 4);365 \\ add(3, 4);
402 \\
403 \\ exit();
404 \\}366 \\}
405 \\367 \\
406 \\fn add(a: u32, b: u32) void {368 \\fn add(a: u32, b: u32) void {
...@@ -427,10 +389,8 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -427,10 +389,8 @@ pub fn addCases(ctx: *TestContext) !void {
427 // Tests copying a register. For the `c = a + b`, it has to389 // Tests copying a register. For the `c = a + b`, it has to
428 // preserve both a and b, because they are both used later.390 // preserve both a and b, because they are both used later.
429 case.addCompareOutput(391 case.addCompareOutput(
430 \\pub export fn _start() noreturn {392 \\pub fn main() void {
431 \\ add(3, 4);393 \\ add(3, 4);
432 \\
433 \\ exit();
434 \\}394 \\}
435 \\395 \\
436 \\fn add(a: u32, b: u32) void {396 \\fn add(a: u32, b: u32) void {
...@@ -443,26 +403,14 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -443,26 +403,14 @@ pub fn addCases(ctx: *TestContext) !void {
443 \\pub fn assert(ok: bool) void {403 \\pub fn assert(ok: bool) void {
444 \\ if (!ok) unreachable; // assertion failure404 \\ if (!ok) unreachable; // assertion failure
445 \\}405 \\}
446 \\
447 \\fn exit() noreturn {
448 \\ asm volatile ("syscall"
449 \\ :
450 \\ : [number] "{rax}" (231),
451 \\ [arg1] "{rdi}" (0)
452 \\ : "rcx", "r11", "memory"
453 \\ );
454 \\ unreachable;
455 \\}
456 ,406 ,
457 "",407 "",
458 );408 );
459409
460 // More stress on the liveness detection.410 // More stress on the liveness detection.
461 case.addCompareOutput(411 case.addCompareOutput(
462 \\pub export fn _start() noreturn {412 \\pub fn main() void {
463 \\ add(3, 4);413 \\ add(3, 4);
464 \\
465 \\ exit();
466 \\}414 \\}
467 \\415 \\
468 \\fn add(a: u32, b: u32) void {416 \\fn add(a: u32, b: u32) void {
...@@ -479,26 +427,14 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -479,26 +427,14 @@ pub fn addCases(ctx: *TestContext) !void {
479 \\pub fn assert(ok: bool) void {427 \\pub fn assert(ok: bool) void {
480 \\ if (!ok) unreachable; // assertion failure428 \\ if (!ok) unreachable; // assertion failure
481 \\}429 \\}
482 \\
483 \\fn exit() noreturn {
484 \\ asm volatile ("syscall"
485 \\ :
486 \\ : [number] "{rax}" (231),
487 \\ [arg1] "{rdi}" (0)
488 \\ : "rcx", "r11", "memory"
489 \\ );
490 \\ unreachable;
491 \\}
492 ,430 ,
493 "",431 "",
494 );432 );
495433
496 // Requires a second move. The register allocator should figure out to re-use rax.434 // Requires a second move. The register allocator should figure out to re-use rax.
497 case.addCompareOutput(435 case.addCompareOutput(
498 \\pub export fn _start() noreturn {436 \\pub fn main() void {
499 \\ add(3, 4);437 \\ add(3, 4);
500 \\
501 \\ exit();
502 \\}438 \\}
503 \\439 \\
504 \\fn add(a: u32, b: u32) void {440 \\fn add(a: u32, b: u32) void {
...@@ -516,27 +452,15 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -516,27 +452,15 @@ pub fn addCases(ctx: *TestContext) !void {
516 \\pub fn assert(ok: bool) void {452 \\pub fn assert(ok: bool) void {
517 \\ if (!ok) unreachable; // assertion failure453 \\ if (!ok) unreachable; // assertion failure
518 \\}454 \\}
519 \\
520 \\fn exit() noreturn {
521 \\ asm volatile ("syscall"
522 \\ :
523 \\ : [number] "{rax}" (231),
524 \\ [arg1] "{rdi}" (0)
525 \\ : "rcx", "r11", "memory"
526 \\ );
527 \\ unreachable;
528 \\}
529 ,455 ,
530 "",456 "",
531 );457 );
532458
533 // Now we test integer return values.459 // Now we test integer return values.
534 case.addCompareOutput(460 case.addCompareOutput(
535 \\pub export fn _start() noreturn {461 \\pub fn main() void {
536 \\ assert(add(3, 4) == 7);462 \\ assert(add(3, 4) == 7);
537 \\ assert(add(20, 10) == 30);463 \\ assert(add(20, 10) == 30);
538 \\
539 \\ exit();
540 \\}464 \\}
541 \\465 \\
542 \\fn add(a: u32, b: u32) u32 {466 \\fn add(a: u32, b: u32) u32 {
...@@ -546,27 +470,15 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -546,27 +470,15 @@ pub fn addCases(ctx: *TestContext) !void {
546 \\pub fn assert(ok: bool) void {470 \\pub fn assert(ok: bool) void {
547 \\ if (!ok) unreachable; // assertion failure471 \\ if (!ok) unreachable; // assertion failure
548 \\}472 \\}
549 \\
550 \\fn exit() noreturn {
551 \\ asm volatile ("syscall"
552 \\ :
553 \\ : [number] "{rax}" (231),
554 \\ [arg1] "{rdi}" (0)
555 \\ : "rcx", "r11", "memory"
556 \\ );
557 \\ unreachable;
558 \\}
559 ,473 ,
560 "",474 "",
561 );475 );
562476
563 // Local mutable variables.477 // Local mutable variables.
564 case.addCompareOutput(478 case.addCompareOutput(
565 \\pub export fn _start() noreturn {479 \\pub fn main() void {
566 \\ assert(add(3, 4) == 7);480 \\ assert(add(3, 4) == 7);
567 \\ assert(add(20, 10) == 30);481 \\ assert(add(20, 10) == 30);
568 \\
569 \\ exit();
570 \\}482 \\}
571 \\483 \\
572 \\fn add(a: u32, b: u32) u32 {484 \\fn add(a: u32, b: u32) u32 {
...@@ -580,39 +492,17 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -580,39 +492,17 @@ pub fn addCases(ctx: *TestContext) !void {
580 \\pub fn assert(ok: bool) void {492 \\pub fn assert(ok: bool) void {
581 \\ if (!ok) unreachable; // assertion failure493 \\ if (!ok) unreachable; // assertion failure
582 \\}494 \\}
583 \\
584 \\fn exit() noreturn {
585 \\ asm volatile ("syscall"
586 \\ :
587 \\ : [number] "{rax}" (231),
588 \\ [arg1] "{rdi}" (0)
589 \\ : "rcx", "r11", "memory"
590 \\ );
591 \\ unreachable;
592 \\}
593 ,495 ,
594 "",496 "",
595 );497 );
596498
597 // Optionals499 // Optionals
598 case.addCompareOutput(500 case.addCompareOutput(
599 \\pub export fn _start() noreturn {501 \\pub fn main() void {
600 \\ const a: u32 = 2;502 \\ const a: u32 = 2;
601 \\ const b: ?u32 = a;503 \\ const b: ?u32 = a;
602 \\ const c = b.?;504 \\ const c = b.?;
603 \\ if (c != 2) unreachable;505 \\ if (c != 2) unreachable;
604 \\
605 \\ exit();
606 \\}
607 \\
608 \\fn exit() noreturn {
609 \\ asm volatile ("syscall"
610 \\ :
611 \\ : [number] "{rax}" (231),
612 \\ [arg1] "{rdi}" (0)
613 \\ : "rcx", "r11", "memory"
614 \\ );
615 \\ unreachable;
616 \\}506 \\}
617 ,507 ,
618 "",508 "",
...@@ -620,12 +510,10 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -620,12 +510,10 @@ pub fn addCases(ctx: *TestContext) !void {
620510
621 // While loops511 // While loops
622 case.addCompareOutput(512 case.addCompareOutput(
623 \\pub export fn _start() noreturn {513 \\pub fn main() void {
624 \\ var i: u32 = 0;514 \\ var i: u32 = 0;
625 \\ while (i < 4) : (i += 1) print();515 \\ while (i < 4) : (i += 1) print();
626 \\ assert(i == 4);516 \\ assert(i == 4);
627 \\
628 \\ exit();
629 \\}517 \\}
630 \\518 \\
631 \\fn print() void {519 \\fn print() void {
...@@ -643,28 +531,16 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -643,28 +531,16 @@ pub fn addCases(ctx: *TestContext) !void {
643 \\pub fn assert(ok: bool) void {531 \\pub fn assert(ok: bool) void {
644 \\ if (!ok) unreachable; // assertion failure532 \\ if (!ok) unreachable; // assertion failure
645 \\}533 \\}
646 \\
647 \\fn exit() noreturn {
648 \\ asm volatile ("syscall"
649 \\ :
650 \\ : [number] "{rax}" (231),
651 \\ [arg1] "{rdi}" (0)
652 \\ : "rcx", "r11", "memory"
653 \\ );
654 \\ unreachable;
655 \\}
656 ,534 ,
657 "hello\nhello\nhello\nhello\n",535 "hello\nhello\nhello\nhello\n",
658 );536 );
659537
660 // inline while requires the condition to be comptime known.538 // inline while requires the condition to be comptime known.
661 case.addError(539 case.addError(
662 \\pub export fn _start() noreturn {540 \\pub fn main() void {
663 \\ var i: u32 = 0;541 \\ var i: u32 = 0;
664 \\ inline while (i < 4) : (i += 1) print();542 \\ inline while (i < 4) : (i += 1) print();
665 \\ assert(i == 4);543 \\ assert(i == 4);
666 \\
667 \\ exit();
668 \\}544 \\}
669 \\545 \\
670 \\fn print() void {546 \\fn print() void {
...@@ -682,24 +558,12 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -682,24 +558,12 @@ pub fn addCases(ctx: *TestContext) !void {
682 \\pub fn assert(ok: bool) void {558 \\pub fn assert(ok: bool) void {
683 \\ if (!ok) unreachable; // assertion failure559 \\ if (!ok) unreachable; // assertion failure
684 \\}560 \\}
685 \\
686 \\fn exit() noreturn {
687 \\ asm volatile ("syscall"
688 \\ :
689 \\ : [number] "{rax}" (231),
690 \\ [arg1] "{rdi}" (0)
691 \\ : "rcx", "r11", "memory"
692 \\ );
693 \\ unreachable;
694 \\}
695 , &[_][]const u8{":3:21: error: unable to resolve comptime value"});561 , &[_][]const u8{":3:21: error: unable to resolve comptime value"});
696562
697 // Labeled blocks (no conditional branch)563 // Labeled blocks (no conditional branch)
698 case.addCompareOutput(564 case.addCompareOutput(
699 \\pub export fn _start() noreturn {565 \\pub fn main() void {
700 \\ assert(add(3, 4) == 20);566 \\ assert(add(3, 4) == 20);
701 \\
702 \\ exit();
703 \\}567 \\}
704 \\568 \\
705 \\fn add(a: u32, b: u32) u32 {569 \\fn add(a: u32, b: u32) u32 {
...@@ -717,26 +581,14 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -717,26 +581,14 @@ pub fn addCases(ctx: *TestContext) !void {
717 \\pub fn assert(ok: bool) void {581 \\pub fn assert(ok: bool) void {
718 \\ if (!ok) unreachable; // assertion failure582 \\ if (!ok) unreachable; // assertion failure
719 \\}583 \\}
720 \\
721 \\fn exit() noreturn {
722 \\ asm volatile ("syscall"
723 \\ :
724 \\ : [number] "{rax}" (231),
725 \\ [arg1] "{rdi}" (0)
726 \\ : "rcx", "r11", "memory"
727 \\ );
728 \\ unreachable;
729 \\}
730 ,584 ,
731 "",585 "",
732 );586 );
733587
734 // This catches a possible bug in the logic for re-using dying operands.588 // This catches a possible bug in the logic for re-using dying operands.
735 case.addCompareOutput(589 case.addCompareOutput(
736 \\pub export fn _start() noreturn {590 \\pub fn main() void {
737 \\ assert(add(3, 4) == 116);591 \\ assert(add(3, 4) == 116);
738 \\
739 \\ exit();
740 \\}592 \\}
741 \\593 \\
742 \\fn add(a: u32, b: u32) u32 {594 \\fn add(a: u32, b: u32) u32 {
...@@ -759,27 +611,15 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -759,27 +611,15 @@ pub fn addCases(ctx: *TestContext) !void {
759 \\pub fn assert(ok: bool) void {611 \\pub fn assert(ok: bool) void {
760 \\ if (!ok) unreachable; // assertion failure612 \\ if (!ok) unreachable; // assertion failure
761 \\}613 \\}
762 \\
763 \\fn exit() noreturn {
764 \\ asm volatile ("syscall"
765 \\ :
766 \\ : [number] "{rax}" (231),
767 \\ [arg1] "{rdi}" (0)
768 \\ : "rcx", "r11", "memory"
769 \\ );
770 \\ unreachable;
771 \\}
772 ,614 ,
773 "",615 "",
774 );616 );
775617
776 // Spilling registers to the stack.618 // Spilling registers to the stack.
777 case.addCompareOutput(619 case.addCompareOutput(
778 \\pub export fn _start() noreturn {620 \\pub fn main() void {
779 \\ assert(add(3, 4) == 1221);621 \\ assert(add(3, 4) == 1221);
780 \\ assert(mul(3, 4) == 21609);622 \\ assert(mul(3, 4) == 21609);
781 \\
782 \\ exit();
783 \\}623 \\}
784 \\624 \\
785 \\fn add(a: u32, b: u32) u32 {625 \\fn add(a: u32, b: u32) u32 {
...@@ -840,27 +680,15 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -840,27 +680,15 @@ pub fn addCases(ctx: *TestContext) !void {
840 \\pub fn assert(ok: bool) void {680 \\pub fn assert(ok: bool) void {
841 \\ if (!ok) unreachable; // assertion failure681 \\ if (!ok) unreachable; // assertion failure
842 \\}682 \\}
843 \\
844 \\fn exit() noreturn {
845 \\ asm volatile ("syscall"
846 \\ :
847 \\ : [number] "{rax}" (231),
848 \\ [arg1] "{rdi}" (0)
849 \\ : "rcx", "r11", "memory"
850 \\ );
851 \\ unreachable;
852 \\}
853 ,683 ,
854 "",684 "",
855 );685 );
856686
857 // Reusing the registers of dead operands playing nicely with conditional branching.687 // Reusing the registers of dead operands playing nicely with conditional branching.
858 case.addCompareOutput(688 case.addCompareOutput(
859 \\pub export fn _start() noreturn {689 \\pub fn main() void {
860 \\ assert(add(3, 4) == 791);690 \\ assert(add(3, 4) == 791);
861 \\ assert(add(4, 3) == 79);691 \\ assert(add(4, 3) == 79);
862 \\
863 \\ exit();
864 \\}692 \\}
865 \\693 \\
866 \\fn add(a: u32, b: u32) u32 {694 \\fn add(a: u32, b: u32) u32 {
...@@ -902,30 +730,18 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -902,30 +730,18 @@ pub fn addCases(ctx: *TestContext) !void {
902 \\pub fn assert(ok: bool) void {730 \\pub fn assert(ok: bool) void {
903 \\ if (!ok) unreachable; // assertion failure731 \\ if (!ok) unreachable; // assertion failure
904 \\}732 \\}
905 \\
906 \\fn exit() noreturn {
907 \\ asm volatile ("syscall"
908 \\ :
909 \\ : [number] "{rax}" (231),
910 \\ [arg1] "{rdi}" (0)
911 \\ : "rcx", "r11", "memory"
912 \\ );
913 \\ unreachable;
914 \\}
915 ,733 ,
916 "",734 "",
917 );735 );
918736
919 // Character literals and multiline strings.737 // Character literals and multiline strings.
920 case.addCompareOutput(738 case.addCompareOutput(
921 \\pub export fn _start() noreturn {739 \\pub fn main() void {
922 \\ const ignore =740 \\ const ignore =
923 \\ \\ cool thx741 \\ \\ cool thx
924 \\ \\742 \\ \\
925 \\ ;743 \\ ;
926 \\ add('ぁ', '\x03');744 \\ add('ぁ', '\x03');
927 \\
928 \\ exit();
929 \\}745 \\}
930 \\746 \\
931 \\fn add(a: u32, b: u32) void {747 \\fn add(a: u32, b: u32) void {
...@@ -935,26 +751,14 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -935,26 +751,14 @@ pub fn addCases(ctx: *TestContext) !void {
935 \\pub fn assert(ok: bool) void {751 \\pub fn assert(ok: bool) void {
936 \\ if (!ok) unreachable; // assertion failure752 \\ if (!ok) unreachable; // assertion failure
937 \\}753 \\}
938 \\
939 \\fn exit() noreturn {
940 \\ asm volatile ("syscall"
941 \\ :
942 \\ : [number] "{rax}" (231),
943 \\ [arg1] "{rdi}" (0)
944 \\ : "rcx", "r11", "memory"
945 \\ );
946 \\ unreachable;
947 \\}
948 ,754 ,
949 "",755 "",
950 );756 );
951757
952 // Global const.758 // Global const.
953 case.addCompareOutput(759 case.addCompareOutput(
954 \\pub export fn _start() noreturn {760 \\pub fn main() void {
955 \\ add(aa, bb);761 \\ add(aa, bb);
956 \\
957 \\ exit();
958 \\}762 \\}
959 \\763 \\
960 \\const aa = 'ぁ';764 \\const aa = 'ぁ';
...@@ -967,41 +771,19 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -967,41 +771,19 @@ pub fn addCases(ctx: *TestContext) !void {
967 \\pub fn assert(ok: bool) void {771 \\pub fn assert(ok: bool) void {
968 \\ if (!ok) unreachable; // assertion failure772 \\ if (!ok) unreachable; // assertion failure
969 \\}773 \\}
970 \\
971 \\fn exit() noreturn {
972 \\ asm volatile ("syscall"
973 \\ :
974 \\ : [number] "{rax}" (231),
975 \\ [arg1] "{rdi}" (0)
976 \\ : "rcx", "r11", "memory"
977 \\ );
978 \\ unreachable;
979 \\}
980 ,774 ,
981 "",775 "",
982 );776 );
983777
984 // Array access.778 // Array access.
985 case.addCompareOutput(779 case.addCompareOutput(
986 \\pub export fn _start() noreturn {780 \\pub fn main() void {
987 \\ assert("hello"[0] == 'h');781 \\ assert("hello"[0] == 'h');
988 \\
989 \\ exit();
990 \\}782 \\}
991 \\783 \\
992 \\pub fn assert(ok: bool) void {784 \\pub fn assert(ok: bool) void {
993 \\ if (!ok) unreachable; // assertion failure785 \\ if (!ok) unreachable; // assertion failure
994 \\}786 \\}
995 \\
996 \\fn exit() noreturn {
997 \\ asm volatile ("syscall"
998 \\ :
999 \\ : [number] "{rax}" (231),
1000 \\ [arg1] "{rdi}" (0)
1001 \\ : "rcx", "r11", "memory"
1002 \\ );
1003 \\ unreachable;
1004 \\}
1005 ,787 ,
1006 "",788 "",
1007 );789 );
...@@ -1009,61 +791,35 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1009,61 +791,35 @@ pub fn addCases(ctx: *TestContext) !void {
1009 // Array access to a global array.791 // Array access to a global array.
1010 case.addCompareOutput(792 case.addCompareOutput(
1011 \\const hello = "hello".*;793 \\const hello = "hello".*;
1012 \\pub export fn _start() noreturn {794 \\pub fn main() void {
1013 \\ assert(hello[1] == 'e');795 \\ assert(hello[1] == 'e');
1014 \\
1015 \\ exit();
1016 \\}796 \\}
1017 \\797 \\
1018 \\pub fn assert(ok: bool) void {798 \\pub fn assert(ok: bool) void {
1019 \\ if (!ok) unreachable; // assertion failure799 \\ if (!ok) unreachable; // assertion failure
1020 \\}800 \\}
1021 \\
1022 \\fn exit() noreturn {
1023 \\ asm volatile ("syscall"
1024 \\ :
1025 \\ : [number] "{rax}" (231),
1026 \\ [arg1] "{rdi}" (0)
1027 \\ : "rcx", "r11", "memory"
1028 \\ );
1029 \\ unreachable;
1030 \\}
1031 ,801 ,
1032 "",802 "",
1033 );803 );
1034804
1035 // 64bit set stack805 // 64bit set stack
1036 case.addCompareOutput(806 case.addCompareOutput(
1037 \\pub export fn _start() noreturn {807 \\pub fn main() void {
1038 \\ var i: u64 = 0xFFEEDDCCBBAA9988;808 \\ var i: u64 = 0xFFEEDDCCBBAA9988;
1039 \\ assert(i == 0xFFEEDDCCBBAA9988);809 \\ assert(i == 0xFFEEDDCCBBAA9988);
1040 \\
1041 \\ exit();
1042 \\}810 \\}
1043 \\811 \\
1044 \\pub fn assert(ok: bool) void {812 \\pub fn assert(ok: bool) void {
1045 \\ if (!ok) unreachable; // assertion failure813 \\ if (!ok) unreachable; // assertion failure
1046 \\}814 \\}
1047 \\
1048 \\fn exit() noreturn {
1049 \\ asm volatile ("syscall"
1050 \\ :
1051 \\ : [number] "{rax}" (231),
1052 \\ [arg1] "{rdi}" (0)
1053 \\ : "rcx", "r11", "memory"
1054 \\ );
1055 \\ unreachable;
1056 \\}
1057 ,815 ,
1058 "",816 "",
1059 );817 );
1060818
1061 // Basic for loop819 // Basic for loop
1062 case.addCompareOutput(820 case.addCompareOutput(
1063 \\pub export fn _start() noreturn {821 \\pub fn main() void {
1064 \\ for ("hello") |_| print();822 \\ for ("hello") |_| print();
1065 \\
1066 \\ exit();
1067 \\}823 \\}
1068 \\824 \\
1069 \\fn print() void {825 \\fn print() void {
...@@ -1077,16 +833,6 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1077,16 +833,6 @@ pub fn addCases(ctx: *TestContext) !void {
1077 \\ );833 \\ );
1078 \\ return;834 \\ return;
1079 \\}835 \\}
1080 \\
1081 \\fn exit() noreturn {
1082 \\ asm volatile ("syscall"
1083 \\ :
1084 \\ : [number] "{rax}" (231),
1085 \\ [arg1] "{rdi}" (0)
1086 \\ : "rcx", "r11", "memory"
1087 \\ );
1088 \\ unreachable;
1089 \\}
1090 ,836 ,
1091 "hello\nhello\nhello\nhello\nhello\n",837 "hello\nhello\nhello\nhello\nhello\n",
1092 );838 );
...@@ -1095,19 +841,8 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1095,19 +841,8 @@ pub fn addCases(ctx: *TestContext) !void {
1095 {841 {
1096 var case = ctx.exe("basic import", linux_x64);842 var case = ctx.exe("basic import", linux_x64);
1097 case.addCompareOutput(843 case.addCompareOutput(
1098 \\pub export fn _start() noreturn {844 \\pub fn main() void {
1099 \\ @import("print.zig").print();845 \\ @import("print.zig").print();
1100 \\ exit();
1101 \\}
1102 \\
1103 \\fn exit() noreturn {
1104 \\ asm volatile ("syscall"
1105 \\ :
1106 \\ : [number] "{rax}" (231),
1107 \\ [arg1] "{rdi}" (@as(usize, 0))
1108 \\ : "rcx", "r11", "memory"
1109 \\ );
1110 \\ unreachable;
1111 \\}846 \\}
1112 ,847 ,
1113 "Hello, World!\n",848 "Hello, World!\n",
...@@ -1132,14 +867,14 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1132,14 +867,14 @@ pub fn addCases(ctx: *TestContext) !void {
1132 {867 {
1133 var case = ctx.exe("redundant comptime", linux_x64);868 var case = ctx.exe("redundant comptime", linux_x64);
1134 case.addError(869 case.addError(
1135 \\pub export fn _start() void {870 \\pub fn main() void {
1136 \\ var a: comptime u32 = 0;871 \\ var a: comptime u32 = 0;
1137 \\}872 \\}
1138 ,873 ,
1139 &.{":2:12: error: redundant comptime keyword in already comptime scope"},874 &.{":2:12: error: redundant comptime keyword in already comptime scope"},
1140 );875 );
1141 case.addError(876 case.addError(
1142 \\pub export fn _start() void {877 \\pub fn main() void {
1143 \\ comptime {878 \\ comptime {
1144 \\ var a: u32 = comptime 0;879 \\ var a: u32 = comptime 0;
1145 \\ }880 \\ }
...@@ -1151,19 +886,8 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1151,19 +886,8 @@ pub fn addCases(ctx: *TestContext) !void {
1151 {886 {
1152 var case = ctx.exe("import private", linux_x64);887 var case = ctx.exe("import private", linux_x64);
1153 case.addError(888 case.addError(
1154 \\pub export fn _start() noreturn {889 \\pub fn main() void {
1155 \\ @import("print.zig").print();890 \\ @import("print.zig").print();
1156 \\ exit();
1157 \\}
1158 \\
1159 \\fn exit() noreturn {
1160 \\ asm volatile ("syscall"
1161 \\ :
1162 \\ : [number] "{rax}" (231),
1163 \\ [arg1] "{rdi}" (@as(usize, 0))
1164 \\ : "rcx", "r11", "memory"
1165 \\ );
1166 \\ unreachable;
1167 \\}891 \\}
1168 ,892 ,
1169 &.{893 &.{
...@@ -1215,19 +939,17 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1215,19 +939,17 @@ pub fn addCases(ctx: *TestContext) !void {
1215 });939 });
1216940
1217 ctx.compileError("compileError", linux_x64,941 ctx.compileError("compileError", linux_x64,
1218 \\pub export fn _start() noreturn {942 \\export fn foo() void {
1219 \\ @compileError("this is an error");943 \\ @compileError("this is an error");
1220 \\ unreachable;
1221 \\}944 \\}
1222 , &[_][]const u8{":2:3: error: this is an error"});945 , &[_][]const u8{":2:3: error: this is an error"});
1223946
1224 {947 {
1225 var case = ctx.obj("variable shadowing", linux_x64);948 var case = ctx.obj("variable shadowing", linux_x64);
1226 case.addError(949 case.addError(
1227 \\export fn _start() noreturn {950 \\pub fn main() void {
1228 \\ var i: u32 = 10;951 \\ var i: u32 = 10;
1229 \\ var i: u32 = 10;952 \\ var i: u32 = 10;
1230 \\ unreachable;
1231 \\}953 \\}
1232 , &[_][]const u8{954 , &[_][]const u8{
1233 ":3:9: error: redeclaration of 'i'",955 ":3:9: error: redeclaration of 'i'",
...@@ -1235,9 +957,8 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1235,9 +957,8 @@ pub fn addCases(ctx: *TestContext) !void {
1235 });957 });
1236 case.addError(958 case.addError(
1237 \\var testing: i64 = 10;959 \\var testing: i64 = 10;
1238 \\pub export fn _start() noreturn {960 \\pub fn main() void {
1239 \\ var testing: i64 = 20;961 \\ var testing: i64 = 20;
1240 \\ unreachable;
1241 \\}962 \\}
1242 , &[_][]const u8{963 , &[_][]const u8{
1243 ":3:9: error: local shadows declaration of 'testing'",964 ":3:9: error: local shadows declaration of 'testing'",
...@@ -1268,7 +989,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1268,7 +989,7 @@ pub fn addCases(ctx: *TestContext) !void {
1268989
1269 // Now only compile log statements remain. One per Decl.990 // Now only compile log statements remain. One per Decl.
1270 case.addError(991 case.addError(
1271 \\pub export fn _start() noreturn {992 \\export fn _start() noreturn {
1272 \\ const b = true;993 \\ const b = true;
1273 \\ var f: u32 = 1;994 \\ var f: u32 = 1;
1274 \\ @compileLog(b, 20, f, x);995 \\ @compileLog(b, 20, f, x);
...@@ -1306,43 +1027,19 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1306,43 +1027,19 @@ pub fn addCases(ctx: *TestContext) !void {
13061027
1307 // Break out of loop1028 // Break out of loop
1308 case.addCompareOutput(1029 case.addCompareOutput(
1309 \\pub export fn _start() noreturn {1030 \\pub fn main() void {
1310 \\ while (true) {1031 \\ while (true) {
1311 \\ break;1032 \\ break;
1312 \\ }1033 \\ }
1313 \\
1314 \\ exit();
1315 \\}
1316 \\
1317 \\fn exit() noreturn {
1318 \\ asm volatile ("syscall"
1319 \\ :
1320 \\ : [number] "{rax}" (231),
1321 \\ [arg1] "{rdi}" (0)
1322 \\ : "rcx", "r11", "memory"
1323 \\ );
1324 \\ unreachable;
1325 \\}1034 \\}
1326 ,1035 ,
1327 "",1036 "",
1328 );1037 );
1329 case.addCompareOutput(1038 case.addCompareOutput(
1330 \\pub export fn _start() noreturn {1039 \\pub fn main() void {
1331 \\ foo: while (true) {1040 \\ foo: while (true) {
1332 \\ break :foo;1041 \\ break :foo;
1333 \\ }1042 \\ }
1334 \\
1335 \\ exit();
1336 \\}
1337 \\
1338 \\fn exit() noreturn {
1339 \\ asm volatile ("syscall"
1340 \\ :
1341 \\ : [number] "{rax}" (231),
1342 \\ [arg1] "{rdi}" (0)
1343 \\ : "rcx", "r11", "memory"
1344 \\ );
1345 \\ unreachable;
1346 \\}1043 \\}
1347 ,1044 ,
1348 "",1045 "",
...@@ -1534,46 +1231,26 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1534,46 +1231,26 @@ pub fn addCases(ctx: *TestContext) !void {
1534 {1231 {
1535 var case = ctx.exe("orelse at comptime", linux_x64);1232 var case = ctx.exe("orelse at comptime", linux_x64);
1536 case.addCompareOutput(1233 case.addCompareOutput(
1537 \\pub export fn _start() noreturn {1234 \\pub fn main() void {
1538 \\ const i: ?u64 = 0;1235 \\ const i: ?u64 = 0;
1539 \\ const orelsed = i orelse 5;1236 \\ const result = i orelse 5;
1540 \\ assert(orelsed == 0);1237 \\ assert(result == 0);
1541 \\ exit();
1542 \\}1238 \\}
1543 \\fn assert(b: bool) void {1239 \\fn assert(b: bool) void {
1544 \\ if (!b) unreachable;1240 \\ if (!b) unreachable;
1545 \\}1241 \\}
1546 \\fn exit() noreturn {
1547 \\ asm volatile ("syscall"
1548 \\ :
1549 \\ : [number] "{rax}" (231),
1550 \\ [arg1] "{rdi}" (0)
1551 \\ : "rcx", "r11", "memory"
1552 \\ );
1553 \\ unreachable;
1554 \\}
1555 ,1242 ,
1556 "",1243 "",
1557 );1244 );
1558 case.addCompareOutput(1245 case.addCompareOutput(
1559 \\pub export fn _start() noreturn {1246 \\pub fn main() void {
1560 \\ const i: ?u64 = null;1247 \\ const i: ?u64 = null;
1561 \\ const orelsed = i orelse 5;1248 \\ const result = i orelse 5;
1562 \\ assert(orelsed == 5);1249 \\ assert(result == 5);
1563 \\ exit();
1564 \\}1250 \\}
1565 \\fn assert(b: bool) void {1251 \\fn assert(b: bool) void {
1566 \\ if (!b) unreachable;1252 \\ if (!b) unreachable;
1567 \\}1253 \\}
1568 \\fn exit() noreturn {
1569 \\ asm volatile ("syscall"
1570 \\ :
1571 \\ : [number] "{rax}" (231),
1572 \\ [arg1] "{rdi}" (0)
1573 \\ : "rcx", "r11", "memory"
1574 \\ );
1575 \\ unreachable;
1576 \\}
1577 ,1254 ,
1578 "",1255 "",
1579 );1256 );
...@@ -1611,20 +1288,10 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1611,20 +1288,10 @@ pub fn addCases(ctx: *TestContext) !void {
1611 {1288 {
1612 var case = ctx.exe("passing u0 to function", linux_x64);1289 var case = ctx.exe("passing u0 to function", linux_x64);
1613 case.addCompareOutput(1290 case.addCompareOutput(
1614 \\pub export fn _start() noreturn {1291 \\pub fn main() void {
1615 \\ doNothing(0);1292 \\ doNothing(0);
1616 \\ exit();
1617 \\}1293 \\}
1618 \\fn doNothing(arg: u0) void {}1294 \\fn doNothing(arg: u0) void {}
1619 \\fn exit() noreturn {
1620 \\ asm volatile ("syscall"
1621 \\ :
1622 \\ : [number] "{rax}" (231),
1623 \\ [arg1] "{rdi}" (0)
1624 \\ : "rcx", "r11", "memory"
1625 \\ );
1626 \\ unreachable;
1627 \\}
1628 ,1295 ,
1629 "",1296 "",
1630 );1297 );
...@@ -1632,119 +1299,67 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1632,119 +1299,67 @@ pub fn addCases(ctx: *TestContext) !void {
1632 {1299 {
1633 var case = ctx.exe("catch at comptime", linux_x64);1300 var case = ctx.exe("catch at comptime", linux_x64);
1634 case.addCompareOutput(1301 case.addCompareOutput(
1635 \\pub export fn _start() noreturn {1302 \\pub fn main() void {
1636 \\ const i: anyerror!u64 = 0;1303 \\ const i: anyerror!u64 = 0;
1637 \\ const caught = i catch 5;1304 \\ const caught = i catch 5;
1638 \\ assert(caught == 0);1305 \\ assert(caught == 0);
1639 \\ exit();
1640 \\}1306 \\}
1641 \\fn assert(b: bool) void {1307 \\fn assert(b: bool) void {
1642 \\ if (!b) unreachable;1308 \\ if (!b) unreachable;
1643 \\}1309 \\}
1644 \\fn exit() noreturn {
1645 \\ asm volatile ("syscall"
1646 \\ :
1647 \\ : [number] "{rax}" (231),
1648 \\ [arg1] "{rdi}" (0)
1649 \\ : "rcx", "r11", "memory"
1650 \\ );
1651 \\ unreachable;
1652 \\}
1653 ,1310 ,
1654 "",1311 "",
1655 );1312 );
16561313
1657 case.addCompareOutput(1314 case.addCompareOutput(
1658 \\pub export fn _start() noreturn {1315 \\pub fn main() void {
1659 \\ const i: anyerror!u64 = error.B;1316 \\ const i: anyerror!u64 = error.B;
1660 \\ const caught = i catch 5;1317 \\ const caught = i catch 5;
1661 \\ assert(caught == 5);1318 \\ assert(caught == 5);
1662 \\ exit();
1663 \\}1319 \\}
1664 \\fn assert(b: bool) void {1320 \\fn assert(b: bool) void {
1665 \\ if (!b) unreachable;1321 \\ if (!b) unreachable;
1666 \\}1322 \\}
1667 \\fn exit() noreturn {
1668 \\ asm volatile ("syscall"
1669 \\ :
1670 \\ : [number] "{rax}" (231),
1671 \\ [arg1] "{rdi}" (0)
1672 \\ : "rcx", "r11", "memory"
1673 \\ );
1674 \\ unreachable;
1675 \\}
1676 ,1323 ,
1677 "",1324 "",
1678 );1325 );
16791326
1680 case.addCompareOutput(1327 case.addCompareOutput(
1681 \\pub export fn _start() noreturn {1328 \\pub fn main() void {
1682 \\ const a: anyerror!comptime_int = 42;1329 \\ const a: anyerror!comptime_int = 42;
1683 \\ const b: *const comptime_int = &(a catch unreachable);1330 \\ const b: *const comptime_int = &(a catch unreachable);
1684 \\ assert(b.* == 42);1331 \\ assert(b.* == 42);
1685 \\
1686 \\ exit();
1687 \\}1332 \\}
1688 \\fn assert(b: bool) void {1333 \\fn assert(b: bool) void {
1689 \\ if (!b) unreachable; // assertion failure1334 \\ if (!b) unreachable; // assertion failure
1690 \\}1335 \\}
1691 \\fn exit() noreturn {
1692 \\ asm volatile ("syscall"
1693 \\ :
1694 \\ : [number] "{rax}" (231),
1695 \\ [arg1] "{rdi}" (0)
1696 \\ : "rcx", "r11", "memory"
1697 \\ );
1698 \\ unreachable;
1699 \\}
1700 , "");1336 , "");
17011337
1702 case.addCompareOutput(1338 case.addCompareOutput(
1703 \\pub export fn _start() noreturn {1339 \\pub fn main() void {
1704 \\ const a: anyerror!u32 = error.B;1340 \\ const a: anyerror!u32 = error.B;
1705 \\ _ = &(a catch |err| assert(err == error.B));1341 \\ _ = &(a catch |err| assert(err == error.B));
1706 \\ exit();
1707 \\}1342 \\}
1708 \\fn assert(b: bool) void {1343 \\fn assert(b: bool) void {
1709 \\ if (!b) unreachable;1344 \\ if (!b) unreachable;
1710 \\}1345 \\}
1711 \\fn exit() noreturn {
1712 \\ asm volatile ("syscall"
1713 \\ :
1714 \\ : [number] "{rax}" (231),
1715 \\ [arg1] "{rdi}" (0)
1716 \\ : "rcx", "r11", "memory"
1717 \\ );
1718 \\ unreachable;
1719 \\}
1720 , "");1346 , "");
17211347
1722 case.addCompareOutput(1348 case.addCompareOutput(
1723 \\pub export fn _start() noreturn {1349 \\pub fn main() void {
1724 \\ const a: anyerror!u32 = error.Bar;1350 \\ const a: anyerror!u32 = error.Bar;
1725 \\ a catch |err| assert(err == error.Bar);1351 \\ a catch |err| assert(err == error.Bar);
1726 \\
1727 \\ exit();
1728 \\}1352 \\}
1729 \\fn assert(b: bool) void {1353 \\fn assert(b: bool) void {
1730 \\ if (!b) unreachable;1354 \\ if (!b) unreachable;
1731 \\}1355 \\}
1732 \\fn exit() noreturn {
1733 \\ asm volatile ("syscall"
1734 \\ :
1735 \\ : [number] "{rax}" (231),
1736 \\ [arg1] "{rdi}" (0)
1737 \\ : "rcx", "r11", "memory"
1738 \\ );
1739 \\ unreachable;
1740 \\}
1741 , "");1356 , "");
1742 }1357 }
1743 {1358 {
1744 var case = ctx.exe("merge error sets", linux_x64);1359 var case = ctx.exe("merge error sets", linux_x64);
17451360
1746 case.addCompareOutput(1361 case.addCompareOutput(
1747 \\pub export fn _start() noreturn {1362 \\pub fn main() void {
1748 \\ const E = error{ A, B, D } || error { A, B, C };1363 \\ const E = error{ A, B, D } || error { A, B, C };
1749 \\ const a = E.A;1364 \\ const a = E.A;
1750 \\ const b = E.B;1365 \\ const b = E.B;
...@@ -1755,20 +1370,10 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1755,20 +1370,10 @@ pub fn addCases(ctx: *TestContext) !void {
1755 \\ const y = E2.Y;1370 \\ const y = E2.Y;
1756 \\ const z = E2.Z;1371 \\ const z = E2.Z;
1757 \\ assert(anyerror || error { Z } == anyerror);1372 \\ assert(anyerror || error { Z } == anyerror);
1758 \\ exit();
1759 \\}1373 \\}
1760 \\fn assert(b: bool) void {1374 \\fn assert(b: bool) void {
1761 \\ if (!b) unreachable;1375 \\ if (!b) unreachable;
1762 \\}1376 \\}
1763 \\fn exit() noreturn {
1764 \\ asm volatile ("syscall"
1765 \\ :
1766 \\ : [number] "{rax}" (231),
1767 \\ [arg1] "{rdi}" (0)
1768 \\ : "rcx", "r11", "memory"
1769 \\ );
1770 \\ unreachable;
1771 \\}
1772 ,1377 ,
1773 "",1378 "",
1774 );1379 );