Skip to content

Commit 2cd6fe8

Browse files
committed
Auto merge of #1921 - RalfJung:overflow-checks-off, r=RalfJung
test for overflow-checks=off Strangely, if we call the functions in `std::ops`, we still get the panics. I assume that is because we build the stdlib with `-Cdebug-assertions=on`; probably the magic attribute that makes stdlib functions inherit overflow checks from the calling crate only works one way (namely to enable them when the calling crate asks for them, but not to disable them when the calling crate does not want them).
2 parents 763a445 + 7dd1f05 commit 2cd6fe8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/run-pass/overflow_checks_off.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// compile-flags: -C overflow-checks=off
2+
3+
// Check that we correctly implement the intended behavior of these operators
4+
// when they are not being overflow-checked.
5+
6+
// FIXME: if we call the functions in `std::ops`, we still get the panics.
7+
// Miri does not implement the codegen-time hack that backs `#[rustc_inherit_overflow_checks]`.
8+
// use std::ops::*;
9+
10+
fn main() {
11+
assert_eq!(-{-0x80i8}, -0x80);
12+
13+
assert_eq!(0xffu8 + 1, 0_u8);
14+
assert_eq!(0u8 - 1, 0xff_u8);
15+
assert_eq!(0xffu8 * 2, 0xfe_u8);
16+
assert_eq!(1u8 << 9, 2_u8);
17+
assert_eq!(2u8 >> 9, 1_u8);
18+
}

0 commit comments

Comments
 (0)