Skip to content

Commit

Permalink
Auto merge of #2914 - RalfJung:unchecked_shl, r=RalfJung
Browse files Browse the repository at this point in the history
add unchecked_shl test

#112238  made me realize that we have a test for add,sub,mul,shr but not shl. Add the missing test. Also name the existing tests more consistently.
  • Loading branch information
bors committed Jun 3, 2023
2 parents 507055b + e13d238 commit df4b808
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/tools/miri/tests/fail/intrinsics/unchecked_shl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(unchecked_math)]

fn main() {
unsafe {
let _n = 1i8.unchecked_shl(8);
//~^ ERROR: overflowing shift by 8 in `unchecked_shl`
}
}
15 changes: 15 additions & 0 deletions src/tools/miri/tests/fail/intrinsics/unchecked_shl.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: Undefined Behavior: overflowing shift by 8 in `unchecked_shl`
--> $DIR/unchecked_shl.rs:LL:CC
|
LL | let _n = 1i8.unchecked_shl(8);
| ^^^^^^^^^^^^^^^^^^^^ overflowing shift by 8 in `unchecked_shl`
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `main` at $DIR/unchecked_shl.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: Undefined Behavior: overflowing shift by 64 in `unchecked_shr`
--> $DIR/overflowing-unchecked-rsh.rs:LL:CC
--> $DIR/unchecked_shr.rs:LL:CC
|
LL | let _n = 1i64.unchecked_shr(64);
| ^^^^^^^^^^^^^^^^^^^^^^ overflowing shift by 64 in `unchecked_shr`
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `main` at $DIR/overflowing-unchecked-rsh.rs:LL:CC
= note: inside `main` at $DIR/unchecked_shr.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

Expand Down

0 comments on commit df4b808

Please sign in to comment.