mirror of
https://github.com/ziglang/zig.git
synced 2025-12-17 19:53:06 +00:00
add runtime safety tests for SIMD integer division
This commit is contained in:
parent
f6cdc94a50
commit
5597b11a52
@ -505,6 +505,21 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
|
|||||||
\\}
|
\\}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
cases.addRuntimeSafety("signed integer division overflow - vectors",
|
||||||
|
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
|
||||||
|
\\ @import("std").os.exit(126);
|
||||||
|
\\}
|
||||||
|
\\pub fn main() !void {
|
||||||
|
\\ var a: @Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 };
|
||||||
|
\\ var b: @Vector(4, i16) = [_]i16{ 1, 2, -1, 4 };
|
||||||
|
\\ const x = div(a, b);
|
||||||
|
\\ if (x[2] == 32767) return error.Whatever;
|
||||||
|
\\}
|
||||||
|
\\fn div(a: @Vector(4, i16), b: @Vector(4, i16)) @Vector(4, i16) {
|
||||||
|
\\ return @divTrunc(a, b);
|
||||||
|
\\}
|
||||||
|
);
|
||||||
|
|
||||||
cases.addRuntimeSafety("signed shift left overflow",
|
cases.addRuntimeSafety("signed shift left overflow",
|
||||||
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
|
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
|
||||||
\\ @import("std").os.exit(126);
|
\\ @import("std").os.exit(126);
|
||||||
@ -569,6 +584,20 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
|
|||||||
\\}
|
\\}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
cases.addRuntimeSafety("integer division by zero - vectors",
|
||||||
|
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
|
||||||
|
\\ @import("std").os.exit(126);
|
||||||
|
\\}
|
||||||
|
\\pub fn main() void {
|
||||||
|
\\ var a: @Vector(4, i32) = [4]i32{111, 222, 333, 444};
|
||||||
|
\\ var b: @Vector(4, i32) = [4]i32{111, 0, 333, 444};
|
||||||
|
\\ const x = div0(a, b);
|
||||||
|
\\}
|
||||||
|
\\fn div0(a: @Vector(4, i32), b: @Vector(4, i32)) @Vector(4, i32) {
|
||||||
|
\\ return @divTrunc(a, b);
|
||||||
|
\\}
|
||||||
|
);
|
||||||
|
|
||||||
cases.addRuntimeSafety("exact division failure",
|
cases.addRuntimeSafety("exact division failure",
|
||||||
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
|
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
|
||||||
\\ @import("std").os.exit(126);
|
\\ @import("std").os.exit(126);
|
||||||
@ -582,6 +611,20 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
|
|||||||
\\}
|
\\}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
cases.addRuntimeSafety("exact division failure - vectors",
|
||||||
|
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
|
||||||
|
\\ @import("std").os.exit(126);
|
||||||
|
\\}
|
||||||
|
\\pub fn main() !void {
|
||||||
|
\\ var a: @Vector(4, i32) = [4]i32{111, 222, 333, 444};
|
||||||
|
\\ var b: @Vector(4, i32) = [4]i32{111, 222, 333, 441};
|
||||||
|
\\ const x = divExact(a, b);
|
||||||
|
\\}
|
||||||
|
\\fn divExact(a: @Vector(4, i32), b: @Vector(4, i32)) @Vector(4, i32) {
|
||||||
|
\\ return @divExact(a, b);
|
||||||
|
\\}
|
||||||
|
);
|
||||||
|
|
||||||
cases.addRuntimeSafety("cast []u8 to bigger slice of wrong size",
|
cases.addRuntimeSafety("cast []u8 to bigger slice of wrong size",
|
||||||
\\const std = @import("std");
|
\\const std = @import("std");
|
||||||
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
|
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user