aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/math.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2025-02-09 08:10:20 -0500
committerAndrew Kelley <andrew@ziglang.org>2025-02-10 17:22:16 -0800
commit5433e0438ce464adea53e4849a80d3854b2a036d (patch)
tree4eca082f73367f4fb6ea53a9ec8bdb7fce3b38ee /test/behavior/math.zig
parent8d078f1ba255eb2a60a7fdef4d73c35a33d24802 (diff)
downloadzig-5433e0438ce464adea53e4849a80d3854b2a036d.tar.gz
zig-5433e0438ce464adea53e4849a80d3854b2a036d.zip
cbe: fix ub triggered by mulw overflowing the promoted type
Closes #21914
Diffstat (limited to 'test/behavior/math.zig')
-rw-r--r--test/behavior/math.zig56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/behavior/math.zig b/test/behavior/math.zig
index fb325a95b6..a658a0559c 100644
--- a/test/behavior/math.zig
+++ b/test/behavior/math.zig
@@ -778,6 +778,62 @@ fn should_not_be_zero(x: f128) !void {
try expect(x != 0.0);
}
+test "umax wrapped squaring" {
+ if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
+
+ {
+ var x: u4 = maxInt(u4);
+ x *%= x;
+ try expect(x == 1);
+ }
+ {
+ var x: u8 = maxInt(u8);
+ x *%= x;
+ try expect(x == 1);
+ }
+ {
+ var x: u12 = maxInt(u12);
+ x *%= x;
+ try expect(x == 1);
+ }
+ {
+ var x: u16 = maxInt(u16);
+ x *%= x;
+ try expect(x == 1);
+ }
+ {
+ var x: u24 = maxInt(u24);
+ x *%= x;
+ try expect(x == 1);
+ }
+ {
+ var x: u32 = maxInt(u32);
+ x *%= x;
+ try expect(x == 1);
+ }
+ {
+ var x: u48 = maxInt(u48);
+ x *%= x;
+ try expect(x == 1);
+ }
+ {
+ var x: u64 = maxInt(u64);
+ x *%= x;
+ try expect(x == 1);
+ }
+ {
+ var x: u96 = maxInt(u96);
+ x *%= x;
+ try expect(x == 1);
+ }
+ {
+ var x: u128 = maxInt(u128);
+ x *%= x;
+ try expect(x == 1);
+ }
+}
+
test "128-bit multiplication" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO