aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-05-12 16:41:20 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-05-12 16:41:20 -0700
commitc9cc09a3bfb45d93b84577238047cd69ef0a7d88 (patch)
tree1686cda92ae0c5d9ae55c02e7755c55d4e6f3c18 /test
parent71afc3088009944fcd8339ac71e69a0b77a781ab (diff)
parent40a47eae65b918866abc9d745f89d837f6a1e591 (diff)
downloadzig-c9cc09a3bfb45d93b84577238047cd69ef0a7d88.tar.gz
zig-c9cc09a3bfb45d93b84577238047cd69ef0a7d88.zip
Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts: * lib/std/os/linux.zig * lib/std/os/windows/bits.zig * src/Module.zig * src/Sema.zig * test/stage2/test.zig Mainly I wanted Jakub's new macOS code for respecting stack size, since we now depend on it for debug builds able to pass one of the test cases for recursive comptime function calls with `@setEvalBranchQuota`. The conflicts were all trivial.
Diffstat (limited to 'test')
-rw-r--r--test/run_translated_c.zig14
-rw-r--r--test/stage2/arm.zig53
-rw-r--r--test/stage2/test.zig130
-rw-r--r--test/stage2/wasm.zig5
-rw-r--r--test/tests.zig17
5 files changed, 196 insertions, 23 deletions
diff --git a/test/run_translated_c.zig b/test/run_translated_c.zig
index 314ef2889d..250f7e67bc 100644
--- a/test/run_translated_c.zig
+++ b/test/run_translated_c.zig
@@ -1476,4 +1476,18 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
\\ return 0;
\\}
, "");
+
+ cases.add("typedef with multiple names",
+ \\#include <stdlib.h>
+ \\typedef struct {
+ \\ char field;
+ \\} a_t, b_t;
+ \\
+ \\int main(void) {
+ \\ a_t a = { .field = 42 };
+ \\ b_t b = a;
+ \\ if (b.field != 42) abort();
+ \\ return 0;
+ \\}
+ , "");
}
diff --git a/test/stage2/arm.zig b/test/stage2/arm.zig
index f4efbd9b2a..31b3c06dcd 100644
--- a/test/stage2/arm.zig
+++ b/test/stage2/arm.zig
@@ -458,4 +458,57 @@ pub fn addCases(ctx: *TestContext) !void {
"",
);
}
+
+ {
+ var case = ctx.exe("spilling registers", linux_arm);
+ case.addCompareOutput(
+ \\export fn _start() noreturn {
+ \\ assert(add(3, 4) == 791);
+ \\ exit();
+ \\}
+ \\
+ \\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;
+ \\}
+ \\
+ \\fn exit() noreturn {
+ \\ asm volatile ("svc #0"
+ \\ :
+ \\ : [number] "{r7}" (1),
+ \\ [arg1] "{r0}" (0)
+ \\ : "memory"
+ \\ );
+ \\ unreachable;
+ \\}
+ ,
+ "",
+ );
+ }
}
diff --git a/test/stage2/test.zig b/test/stage2/test.zig
index 440042798f..32bf36d9bb 100644
--- a/test/stage2/test.zig
+++ b/test/stage2/test.zig
@@ -319,6 +319,81 @@ pub fn addCases(ctx: *TestContext) !void {
}
{
+ var case = ctx.exe("multiplying numbers at runtime and comptime", linux_x64);
+ case.addCompareOutput(
+ \\export fn _start() noreturn {
+ \\ mul(3, 4);
+ \\
+ \\ exit();
+ \\}
+ \\
+ \\fn mul(a: u32, b: u32) void {
+ \\ if (a * b != 12) unreachable;
+ \\}
+ \\
+ \\fn exit() noreturn {
+ \\ asm volatile ("syscall"
+ \\ :
+ \\ : [number] "{rax}" (231),
+ \\ [arg1] "{rdi}" (0)
+ \\ : "rcx", "r11", "memory"
+ \\ );
+ \\ unreachable;
+ \\}
+ ,
+ "",
+ );
+ // comptime function call
+ case.addCompareOutput(
+ \\export fn _start() noreturn {
+ \\ exit();
+ \\}
+ \\
+ \\fn mul(a: u32, b: u32) u32 {
+ \\ return a * b;
+ \\}
+ \\
+ \\const x = mul(3, 4);
+ \\
+ \\fn exit() noreturn {
+ \\ asm volatile ("syscall"
+ \\ :
+ \\ : [number] "{rax}" (231),
+ \\ [arg1] "{rdi}" (x - 12)
+ \\ : "rcx", "r11", "memory"
+ \\ );
+ \\ unreachable;
+ \\}
+ ,
+ "",
+ );
+ // Inline function call
+ case.addCompareOutput(
+ \\export fn _start() noreturn {
+ \\ var x: usize = 5;
+ \\ const y = mul(2, 3, x);
+ \\ exit(y - 30);
+ \\}
+ \\
+ \\fn mul(a: usize, b: usize, c: usize) callconv(.Inline) usize {
+ \\ return a * b * c;
+ \\}
+ \\
+ \\fn exit(code: usize) noreturn {
+ \\ asm volatile ("syscall"
+ \\ :
+ \\ : [number] "{rax}" (231),
+ \\ [arg1] "{rdi}" (code)
+ \\ : "rcx", "r11", "memory"
+ \\ );
+ \\ unreachable;
+ \\}
+ ,
+ "",
+ );
+ }
+
+ {
var case = ctx.exe("assert function", linux_x64);
case.addCompareOutput(
\\pub export fn _start() noreturn {
@@ -700,7 +775,8 @@ pub fn addCases(ctx: *TestContext) !void {
// Spilling registers to the stack.
case.addCompareOutput(
\\pub export fn _start() noreturn {
- \\ assert(add(3, 4) == 791);
+ \\ assert(add(3, 4) == 1221);
+ \\ assert(mul(3, 4) == 21609);
\\
\\ exit();
\\}
@@ -716,19 +792,47 @@ pub fn addCases(ctx: *TestContext) !void {
\\ 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 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; // 788
- \\ const z = y + a; // 791
+ \\ const y = x * a; // 7203
+ \\ const z = y * a; // 21609
\\ return z;
\\}
\\
diff --git a/test/stage2/wasm.zig b/test/stage2/wasm.zig
index ccf2661b44..880587d93f 100644
--- a/test/stage2/wasm.zig
+++ b/test/stage2/wasm.zig
@@ -58,7 +58,10 @@ pub fn addCases(ctx: *TestContext) !void {
,
// This is what you get when you take the bits of the IEE-754
// representation of 42.0 and reinterpret them as an unsigned
- // integer. Guess that's a bug in wasmtime.
+ // integer.
+ // Bug is fixed in wasmtime v0.26 but updating to v0.26 is blocked
+ // on this issue:
+ // https://github.com/ziglang/zig/issues/8742
"1109917696\n",
);
diff --git a/test/tests.zig b/test/tests.zig
index b6168f04e2..2ea27af2ca 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -98,15 +98,14 @@ const test_targets = blk: {
},
.link_libc = true,
},
- // https://github.com/ziglang/zig/issues/4926
- //TestTarget{
- // .target = .{
- // .cpu_arch = .i386,
- // .os_tag = .linux,
- // .abi = .gnu,
- // },
- // .link_libc = true,
- //},
+ TestTarget{
+ .target = .{
+ .cpu_arch = .i386,
+ .os_tag = .linux,
+ .abi = .gnu,
+ },
+ .link_libc = true,
+ },
TestTarget{
.target = .{