| ... | ... | @@ -378,4 +378,45 @@ pub fn addCases(ctx: *TestContext) !void { |
| 378 | 378 | "", |
| 379 | 379 | ); |
| 380 | 380 | } |
| 381 | |
| 382 | { |
| 383 | var case = ctx.exe("save function return values in callee preserved register", linux_arm); |
| 384 | // Here, it is necessary to save the result of bar() into a |
| 385 | // callee preserved register, otherwise it will be overwritten |
| 386 | // by the first parameter to baz. |
| 387 | case.addCompareOutput( |
| 388 | \\export fn _start() noreturn { |
| 389 | \\ assert(foo() == 43); |
| 390 | \\ exit(); |
| 391 | \\} |
| 392 | \\ |
| 393 | \\fn foo() u32 { |
| 394 | \\ return bar() + baz(42); |
| 395 | \\} |
| 396 | \\ |
| 397 | \\fn bar() u32 { |
| 398 | \\ return 1; |
| 399 | \\} |
| 400 | \\ |
| 401 | \\fn baz(x: u32) u32 { |
| 402 | \\ return x; |
| 403 | \\} |
| 404 | \\ |
| 405 | \\fn assert(ok: bool) void { |
| 406 | \\ if (!ok) unreachable; |
| 407 | \\} |
| 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 | , |
| 419 | "", |
| 420 | ); |
| 421 | } |
| 381 | 422 | } |