diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-02-22 13:28:57 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-02-22 13:28:57 -0500 |
| commit | 52bb71867d8d6e738eefb7dafead875eb21a4ae7 (patch) | |
| tree | 317c8b0f23e603c590f943700587c3a6596bc8ff /test/runtime_safety.zig | |
| parent | 2fe8a0831f2830a3357cdf65b2ebfe1214b13a83 (diff) | |
| download | zig-52bb71867d8d6e738eefb7dafead875eb21a4ae7.tar.gz zig-52bb71867d8d6e738eefb7dafead875eb21a4ae7.zip | |
implement vector negation
also fix vector behavior tests, they weren't actually testing
runtime vectors, but now they are.
See #903
Diffstat (limited to 'test/runtime_safety.zig')
| -rw-r--r-- | test/runtime_safety.zig | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/runtime_safety.zig b/test/runtime_safety.zig index 12cac64b3a..0427efabd5 100644 --- a/test/runtime_safety.zig +++ b/test/runtime_safety.zig @@ -118,6 +118,47 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\} ); + cases.addRuntimeSafety("vector integer subtraction overflow", + \\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, u32) = []u32{ 1, 2, 8, 4 }; + \\ var b: @Vector(4, u32) = []u32{ 5, 6, 7, 8 }; + \\ const x = sub(b, a); + \\} + \\fn sub(a: @Vector(4, u32), b: @Vector(4, u32)) @Vector(4, u32) { + \\ return a - b; + \\} + ); + + cases.addRuntimeSafety("vector integer multiplication overflow", + \\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, u8) = []u8{ 1, 2, 200, 4 }; + \\ var b: @Vector(4, u8) = []u8{ 5, 6, 2, 8 }; + \\ const x = mul(b, a); + \\} + \\fn mul(a: @Vector(4, u8), b: @Vector(4, u8)) @Vector(4, u8) { + \\ return a * b; + \\} + ); + + cases.addRuntimeSafety("vector integer negation overflow", + \\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, -32768, 200, 4 }; + \\ const x = neg(a); + \\} + \\fn neg(a: @Vector(4, i16)) @Vector(4, i16) { + \\ return -a; + \\} + ); + cases.addRuntimeSafety("integer subtraction overflow", \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { \\ @import("std").os.exit(126); |
