aboutsummaryrefslogtreecommitdiff
path: root/test/run_tests.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-05-06 15:46:38 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-05-06 15:46:38 -0700
commit100802cdc0a898b948d30b464ac2348be1928080 (patch)
tree00aea62fb0d7a5b63637fc7a73f3f3be47f70fc8 /test/run_tests.cpp
parent0c96920172dee530f445e4ef304954d0fe233bfa (diff)
downloadzig-100802cdc0a898b948d30b464ac2348be1928080.tar.gz
zig-100802cdc0a898b948d30b464ac2348be1928080.zip
add debug safety for left shifting
See #46
Diffstat (limited to 'test/run_tests.cpp')
-rw-r--r--test/run_tests.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/run_tests.cpp b/test/run_tests.cpp
index 6c898533cb..81911671b6 100644
--- a/test/run_tests.cpp
+++ b/test/run_tests.cpp
@@ -1363,6 +1363,26 @@ fn neg(a: i16) -> i16 {
}
)SOURCE");
+ add_debug_safety_case("signed shift left overflow", R"SOURCE(
+pub fn main(args: [][]u8) -> %void {
+ shl(-16385, 1);
+}
+#static_eval_enable(false)
+fn shl(a: i16, b: i16) -> i16 {
+ a << b
+}
+ )SOURCE");
+
+ add_debug_safety_case("unsigned shift left overflow", R"SOURCE(
+pub fn main(args: [][]u8) -> %void {
+ shl(0b0010111111111111, 3);
+}
+#static_eval_enable(false)
+fn shl(a: u16, b: u16) -> u16 {
+ a << b
+}
+ )SOURCE");
+
}
//////////////////////////////////////////////////////////////////////////////