aboutsummaryrefslogtreecommitdiff
path: root/test/debug_safety.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-08-09 10:09:38 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-08-09 10:09:38 -0400
commit35d3444e2742faa3c2e805cdcbfeceaf0287eefc (patch)
tree408182308c5f962660f200c59b2619be8d194ffc /test/debug_safety.zig
parent54675b060ae6139f60e111521b9a2688f66977a0 (diff)
downloadzig-35d3444e2742faa3c2e805cdcbfeceaf0287eefc.tar.gz
zig-35d3444e2742faa3c2e805cdcbfeceaf0287eefc.zip
more intuitive left shift and right shift operators
Before: * << is left shift, not allowed to shift 1 bits out * <<% is left shift, allowed to shift 1 bits out * >> is right shift, allowed to shift 1 bits out After: * << is left shift, allowed to shift 1 bits out * >> is right shift, allowed to shift 1 bits out * @shlExact is left shift, not allowed to shift 1 bits out * @shrExact is right shift, not allowed to shift 1 bits out Closes #413
Diffstat (limited to 'test/debug_safety.zig')
-rw-r--r--test/debug_safety.zig34
1 files changed, 32 insertions, 2 deletions
diff --git a/test/debug_safety.zig b/test/debug_safety.zig
index 3df411f7cd..60b92955a8 100644
--- a/test/debug_safety.zig
+++ b/test/debug_safety.zig
@@ -112,7 +112,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\ if (x == 0) return error.Whatever;
\\}
\\fn shl(a: i16, b: i16) -> i16 {
- \\ a << b
+ \\ @shlExact(a, b)
\\}
);
@@ -127,7 +127,37 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\ if (x == 0) return error.Whatever;
\\}
\\fn shl(a: u16, b: u16) -> u16 {
- \\ a << b
+ \\ @shlExact(a, b)
+ \\}
+ );
+
+ cases.addDebugSafety("signed shift right overflow",
+ \\pub fn panic(message: []const u8) -> noreturn {
+ \\ @breakpoint();
+ \\ while (true) {}
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = shr(-16385, 1);
+ \\ if (x == 0) return error.Whatever;
+ \\}
+ \\fn shr(a: i16, b: i16) -> i16 {
+ \\ @shrExact(a, b)
+ \\}
+ );
+
+ cases.addDebugSafety("unsigned shift right overflow",
+ \\pub fn panic(message: []const u8) -> noreturn {
+ \\ @breakpoint();
+ \\ while (true) {}
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = shr(0b0010111111111111, 3);
+ \\ if (x == 0) return error.Whatever;
+ \\}
+ \\fn shr(a: u16, b: u16) -> u16 {
+ \\ @shrExact(a, b)
\\}
);