]> git.lizzy.rs Git - rust.git/blob - src/test/run-fail/overflowing-lsh-4.rs
Auto merge of #63994 - Centril:refactor-qualify-consts, r=spastorino,oli-obk
[rust.git] / src / test / run-fail / overflowing-lsh-4.rs
1 // error-pattern:thread 'main' panicked at 'attempt to shift left with overflow'
2 // compile-flags: -C debug-assertions
3
4 // This function is checking that our automatic truncation does not
5 // sidestep the overflow checking.
6
7 #![warn(exceeding_bitshifts)]
8
9 fn main() {
10     // this signals overflow when checking is on
11     let x = 1_i8 << 17;
12
13     // ... but when checking is off, the fallback will truncate the
14     // input to its lower three bits (= 1). Note that this is *not*
15     // the behavior of the x86 processor for 8- and 16-bit types,
16     // but it is necessary to avoid undefined behavior from LLVM.
17     //
18     // We check that here, by ensuring the result has only been
19     // shifted by one place; if overflow checking is turned off, then
20     // this assertion will pass (and the compiletest driver will
21     // report that the test did not produce the error expected above).
22     assert_eq!(x, 2_i8);
23 }