diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-02-12 20:36:55 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-12 20:36:55 +0100 |
| commit | 29dd5df791bb70d6c5d3d1118c1289d4f3d51899 (patch) | |
| tree | be69c58038568bd2ac24cc8e76858ab08d83f32b /src/test/ui/issues | |
| parent | 2a3c1a30c84d66ad9bde8aef7727dfd6b60c40c9 (diff) | |
| parent | c561d23a6105122a517c14394a46c3faab8e01b6 (diff) | |
| download | rust-29dd5df791bb70d6c5d3d1118c1289d4f3d51899.tar.gz rust-29dd5df791bb70d6c5d3d1118c1289d4f3d51899.zip | |
Rollup merge of #69002 - RalfJung:miri-op-overflow, r=oli-obk,wesleywiser
miri: improve and simplify overflow detection This simplifies the overflow detection for signed binary operators, and adds overflow detection to unary operators so that const-prop doesn't have to crudely hand-roll that. It also fixes some bugs in the operator implementation that however, I think, were not observable. r? @oli-obk @wesleywiser
Diffstat (limited to 'src/test/ui/issues')
| -rw-r--r-- | src/test/ui/issues/issue-8460-const.rs | 12 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-8460-const.stderr | 78 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-8460-const2.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-8460-const2.stderr | 56 |
4 files changed, 117 insertions, 39 deletions
diff --git a/src/test/ui/issues/issue-8460-const.rs b/src/test/ui/issues/issue-8460-const.rs index c18a0d4d6cb..5866cef2d2c 100644 --- a/src/test/ui/issues/issue-8460-const.rs +++ b/src/test/ui/issues/issue-8460-const.rs @@ -3,7 +3,7 @@ #![deny(const_err)] -use std::{isize, i8, i16, i32, i64}; +use std::{isize, i8, i16, i32, i64, i128}; use std::thread; fn main() { @@ -22,6 +22,9 @@ fn main() { assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); //~^ ERROR attempt to divide with overflow //~| ERROR this expression will panic at runtime + assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); + //~^ ERROR attempt to divide with overflow + //~| ERROR this expression will panic at runtime assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); //~^ ERROR attempt to divide by zero assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); @@ -32,6 +35,8 @@ fn main() { //~^ ERROR attempt to divide by zero assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); //~^ ERROR attempt to divide by zero + assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); + //~^ ERROR attempt to divide by zero assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); //~^ ERROR attempt to calculate the remainder with overflow //~| ERROR this expression will panic at runtime @@ -47,6 +52,9 @@ fn main() { assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); //~^ ERROR attempt to calculate the remainder with overflow //~| ERROR this expression will panic at runtime + assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); + //~^ ERROR attempt to calculate the remainder with overflow + //~| ERROR this expression will panic at runtime assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); //~^ ERROR attempt to calculate the remainder with a divisor of zero assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); @@ -57,4 +65,6 @@ fn main() { //~^ ERROR attempt to calculate the remainder with a divisor of zero assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); //~^ ERROR attempt to calculate the remainder with a divisor of zero + assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); + //~^ ERROR attempt to calculate the remainder with a divisor of zero } diff --git a/src/test/ui/issues/issue-8460-const.stderr b/src/test/ui/issues/issue-8460-const.stderr index 6b1d74094a1..d7373948cb9 100644 --- a/src/test/ui/issues/issue-8460-const.stderr +++ b/src/test/ui/issues/issue-8460-const.stderr @@ -64,125 +64,161 @@ error: this expression will panic at runtime LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); | ^^^^^^^^^^^^^ attempt to divide with overflow -error: attempt to divide by zero +error: attempt to divide with overflow + --> $DIR/issue-8460-const.rs:25:36 + | +LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ + +error: this expression will panic at runtime --> $DIR/issue-8460-const.rs:25:36 | +LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ attempt to divide with overflow + +error: attempt to divide by zero + --> $DIR/issue-8460-const.rs:28:36 + | LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); | ^^^^^^^^^^ error: attempt to divide by zero - --> $DIR/issue-8460-const.rs:27:36 + --> $DIR/issue-8460-const.rs:30:36 | LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); | ^^^^^^^ error: attempt to divide by zero - --> $DIR/issue-8460-const.rs:29:36 + --> $DIR/issue-8460-const.rs:32:36 | LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); | ^^^^^^^^ error: attempt to divide by zero - --> $DIR/issue-8460-const.rs:31:36 + --> $DIR/issue-8460-const.rs:34:36 | LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); | ^^^^^^^^ error: attempt to divide by zero - --> $DIR/issue-8460-const.rs:33:36 + --> $DIR/issue-8460-const.rs:36:36 | LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); | ^^^^^^^^ +error: attempt to divide by zero + --> $DIR/issue-8460-const.rs:38:36 + | +LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); + | ^^^^^^^^^ + error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const.rs:35:36 + --> $DIR/issue-8460-const.rs:40:36 | LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^^^^ error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:35:36 + --> $DIR/issue-8460-const.rs:40:36 | LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const.rs:38:36 + --> $DIR/issue-8460-const.rs:43:36 | LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^ error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:38:36 + --> $DIR/issue-8460-const.rs:43:36 | LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^ attempt to calculate the remainder with overflow error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const.rs:41:36 + --> $DIR/issue-8460-const.rs:46:36 | LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^^ error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:41:36 + --> $DIR/issue-8460-const.rs:46:36 | LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const.rs:44:36 + --> $DIR/issue-8460-const.rs:49:36 | LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^^ error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:44:36 + --> $DIR/issue-8460-const.rs:49:36 | LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const.rs:47:36 + --> $DIR/issue-8460-const.rs:52:36 | LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^^ error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:47:36 + --> $DIR/issue-8460-const.rs:52:36 | LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow +error: attempt to calculate the remainder with overflow + --> $DIR/issue-8460-const.rs:55:36 + | +LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ + +error: this expression will panic at runtime + --> $DIR/issue-8460-const.rs:55:36 + | +LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const.rs:50:36 + --> $DIR/issue-8460-const.rs:58:36 | LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); | ^^^^^^^^^^ error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const.rs:52:36 + --> $DIR/issue-8460-const.rs:60:36 | LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); | ^^^^^^^ error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const.rs:54:36 + --> $DIR/issue-8460-const.rs:62:36 | LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); | ^^^^^^^^ error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const.rs:56:36 + --> $DIR/issue-8460-const.rs:64:36 | LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); | ^^^^^^^^ error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const.rs:58:36 + --> $DIR/issue-8460-const.rs:66:36 | LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); | ^^^^^^^^ -error: aborting due to 30 previous errors +error: attempt to calculate the remainder with a divisor of zero + --> $DIR/issue-8460-const.rs:68:36 + | +LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); + | ^^^^^^^^^ + +error: aborting due to 36 previous errors diff --git a/src/test/ui/issues/issue-8460-const2.rs b/src/test/ui/issues/issue-8460-const2.rs index 0ca850abc1b..afea859bb65 100644 --- a/src/test/ui/issues/issue-8460-const2.rs +++ b/src/test/ui/issues/issue-8460-const2.rs @@ -3,7 +3,7 @@ #![deny(const_err)] -use std::{isize, i8, i16, i32, i64}; +use std::{isize, i8, i16, i32, i64, i128}; use std::thread; fn main() { @@ -17,6 +17,8 @@ fn main() { //~^ ERROR attempt to divide with overflow assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); //~^ ERROR attempt to divide with overflow + assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); + //~^ ERROR attempt to divide with overflow assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); //~^ ERROR attempt to divide by zero assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); @@ -27,6 +29,8 @@ fn main() { //~^ ERROR attempt to divide by zero assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); //~^ ERROR attempt to divide by zero + assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); + //~^ ERROR attempt to divide by zero assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); //~^ ERROR attempt to calculate the remainder with overflow assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); @@ -37,6 +41,8 @@ fn main() { //~^ ERROR attempt to calculate the remainder with overflow assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); //~^ ERROR attempt to calculate the remainder with overflow + assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); + //~^ ERROR attempt to calculate the remainder with overflow assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); //~^ ERROR attempt to calculate the remainder with a divisor of zero assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); @@ -47,4 +53,6 @@ fn main() { //~^ ERROR attempt to calculate the remainder with a divisor of zero assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); //~^ ERROR attempt to calculate the remainder with a divisor of zero + assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); + //~^ ERROR attempt to calculate the remainder with a divisor of zero } diff --git a/src/test/ui/issues/issue-8460-const2.stderr b/src/test/ui/issues/issue-8460-const2.stderr index 63b9123e950..e25d560fe0c 100644 --- a/src/test/ui/issues/issue-8460-const2.stderr +++ b/src/test/ui/issues/issue-8460-const2.stderr @@ -34,95 +34,119 @@ error: attempt to divide with overflow LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); | ^^^^^^^^^^^^^ -error: attempt to divide by zero +error: attempt to divide with overflow --> $DIR/issue-8460-const2.rs:20:36 | +LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ + +error: attempt to divide by zero + --> $DIR/issue-8460-const2.rs:22:36 + | LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); | ^^^^^^^^^^ error: attempt to divide by zero - --> $DIR/issue-8460-const2.rs:22:36 + --> $DIR/issue-8460-const2.rs:24:36 | LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); | ^^^^^^^ error: attempt to divide by zero - --> $DIR/issue-8460-const2.rs:24:36 + --> $DIR/issue-8460-const2.rs:26:36 | LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); | ^^^^^^^^ error: attempt to divide by zero - --> $DIR/issue-8460-const2.rs:26:36 + --> $DIR/issue-8460-const2.rs:28:36 | LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); | ^^^^^^^^ error: attempt to divide by zero - --> $DIR/issue-8460-const2.rs:28:36 + --> $DIR/issue-8460-const2.rs:30:36 | LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); | ^^^^^^^^ +error: attempt to divide by zero + --> $DIR/issue-8460-const2.rs:32:36 + | +LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); + | ^^^^^^^^^ + error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const2.rs:30:36 + --> $DIR/issue-8460-const2.rs:34:36 | LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^^^^ error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const2.rs:32:36 + --> $DIR/issue-8460-const2.rs:36:36 | LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^ error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const2.rs:34:36 + --> $DIR/issue-8460-const2.rs:38:36 | LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^^ error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const2.rs:36:36 + --> $DIR/issue-8460-const2.rs:40:36 | LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^^ error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const2.rs:38:36 + --> $DIR/issue-8460-const2.rs:42:36 | LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); | ^^^^^^^^^^^^^ +error: attempt to calculate the remainder with overflow + --> $DIR/issue-8460-const2.rs:44:36 + | +LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ + error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const2.rs:40:36 + --> $DIR/issue-8460-const2.rs:46:36 | LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); | ^^^^^^^^^^ error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const2.rs:42:36 + --> $DIR/issue-8460-const2.rs:48:36 | LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); | ^^^^^^^ error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const2.rs:44:36 + --> $DIR/issue-8460-const2.rs:50:36 | LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); | ^^^^^^^^ error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const2.rs:46:36 + --> $DIR/issue-8460-const2.rs:52:36 | LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); | ^^^^^^^^ error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const2.rs:48:36 + --> $DIR/issue-8460-const2.rs:54:36 | LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); | ^^^^^^^^ -error: aborting due to 20 previous errors +error: attempt to calculate the remainder with a divisor of zero + --> $DIR/issue-8460-const2.rs:56:36 + | +LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); + | ^^^^^^^^^ + +error: aborting due to 24 previous errors |
