aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatt Knight <mattnite@protonmail.com>2021-04-10 14:21:59 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-07-08 09:56:40 -0700
commitfb16633ecb496f3f30cdac11987baad40b7793b2 (patch)
tree96d0b726a2fac3faa5f13777652806d846916025 /test
parent62d27fcfb687e3ab1f10c72513e19529d8ffceed (diff)
downloadzig-fb16633ecb496f3f30cdac11987baad40b7793b2.tar.gz
zig-fb16633ecb496f3f30cdac11987baad40b7793b2.zip
C backend: add/sub/mul wrapping for the C backend
Diffstat (limited to 'test')
-rw-r--r--test/stage2/cbe.zig49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/stage2/cbe.zig b/test/stage2/cbe.zig
index cbe24d3ec3..abf8b0165d 100644
--- a/test/stage2/cbe.zig
+++ b/test/stage2/cbe.zig
@@ -824,6 +824,55 @@ pub fn addCases(ctx: *TestContext) !void {
, "");
}
+ {
+ // TODO: move these cases into the programs themselves once stage 2 has array literals
+ // TODO: add u64 tests, ran into issues with the literal generated for std.math.maxInt(u64)
+ var case = ctx.exeFromCompiledC("Wrapping operations", .{});
+ const programs = comptime blk: {
+ const cases = .{
+ // Addition
+ .{ u3, "+%", 1, 1, 2 },
+ .{ u3, "+%", 7, 1, 0 },
+ .{ i3, "+%", 1, 1, 2 },
+ .{ i3, "+%", 3, 2, -3 },
+ .{ i3, "+%", -3, -2, 3 },
+ .{ c_int, "+%", 1, 1, 2 },
+ .{ c_int, "+%", std.math.maxInt(c_int), 2, std.math.minInt(c_int) + 1 },
+ .{ c_int, "+%", std.math.minInt(c_int) + 1, -2, std.math.maxInt(c_int) },
+
+ // Subtraction
+ .{ u3, "-%", 2, 1, 1 },
+ .{ u3, "-%", 0, 1, 7 },
+ .{ i3, "-%", 2, 1, 1 },
+ .{ i3, "-%", 3, -2, -3 },
+ .{ i3, "-%", -3, 2, 3 },
+ .{ c_int, "-%", 2, 1, 1 },
+ .{ c_int, "-%", std.math.maxInt(c_int), -2, std.math.minInt(c_int) + 1 },
+ .{ c_int, "-%", std.math.minInt(c_int) + 1, 2, std.math.maxInt(c_int) },
+ };
+
+ var ret: [cases.len][:0]const u8 = undefined;
+ for (cases) |c, i| ret[i] = std.fmt.comptimePrint(
+ \\export fn main() i32 {{
+ \\ var lhs: {0} = {2};
+ \\ var rhs: {0} = {3};
+ \\ var expected: {0} = {4};
+ \\
+ \\ if (expected != lhs {1s} rhs) {{
+ \\ return 1;
+ \\ }} else {{
+ \\ return 0;
+ \\ }}
+ \\}}
+ \\
+ , c);
+
+ break :blk ret;
+ };
+
+ inline for (programs) |prog| case.addCompareOutput(prog, "");
+ }
+
ctx.h("simple header", linux_x64,
\\export fn start() void{}
,