Auto merge of #2438 - RalfJung:more-track-caller, r=RalfJung

adjust for more backtrace pruning

The Miri side of https://github.com/rust-lang/rust/pull/99690. Those messages are much nicer. :) And we also need error-pattern much less.
This commit is contained in:
bors 2022-07-25 14:38:57 +00:00
commit b938529fb8
46 changed files with 110 additions and 205 deletions

View File

@ -1 +1 @@
7fe022f5aa32bbbb33c3a58755729d6667a461a9
2fdbf075cf502431ca9fee6616331b32e34f25de

View File

@ -1,4 +1,3 @@
//@error-pattern: overflow computing total size
use std::mem;
fn main() {
@ -6,5 +5,6 @@ fn main() {
let mut y = 0;
unsafe {
(&mut y as *mut i32).copy_from(&x, 1usize << (mem::size_of::<usize>() * 8 - 1));
//~^ERROR: overflow computing total size
}
}

View File

@ -1,19 +1,13 @@
error: Undefined Behavior: overflow computing total size of `copy`
--> RUSTLIB/core/src/intrinsics.rs:LL:CC
--> $DIR/copy_overflow.rs:LL:CC
|
LL | copy(src, dst, count)
| ^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy`
LL | (&mut y as *mut i32).copy_from(&x, 1usize << (mem::size_of::<usize>() * 8 - 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy`
|
= 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 `std::intrinsics::copy::<i32>` at RUSTLIB/core/src/intrinsics.rs:LL:CC
= note: inside `std::ptr::mut_ptr::<impl *mut i32>::copy_from` at RUSTLIB/core/src/ptr/mut_ptr.rs:LL:CC
note: inside `main` at $DIR/copy_overflow.rs:LL:CC
--> $DIR/copy_overflow.rs:LL:CC
|
LL | (&mut y as *mut i32).copy_from(&x, 1usize << (mem::size_of::<usize>() * 8 - 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: inside `main` at $DIR/copy_overflow.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -1,8 +1,7 @@
//@error-pattern: pointer to 5 bytes starting at offset 0 is out-of-bounds
fn main() {
let v = [0i8; 4];
let x = &v as *const i8;
// The error is inside another function, so we cannot match it by line
let x = unsafe { x.offset(5) };
let x = unsafe { x.offset(5) }; //~ERROR: pointer to 5 bytes starting at offset 0 is out-of-bounds
panic!("this should never print: {:?}", x);
}

View File

@ -1,18 +1,13 @@
error: Undefined Behavior: out-of-bounds pointer arithmetic: ALLOC has size 4, so pointer to 5 bytes starting at offset 0 is out-of-bounds
--> RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC
--> $DIR/out_of_bounds_ptr_1.rs:LL:CC
|
LL | unsafe { intrinsics::offset(self, count) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: ALLOC has size 4, so pointer to 5 bytes starting at offset 0 is out-of-bounds
LL | let x = unsafe { x.offset(5) };
| ^^^^^^^^^^^ out-of-bounds pointer arithmetic: ALLOC has size 4, so pointer to 5 bytes starting at offset 0 is out-of-bounds
|
= 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 `std::ptr::const_ptr::<impl *const i8>::offset` at RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC
note: inside `main` at $DIR/out_of_bounds_ptr_1.rs:LL:CC
--> $DIR/out_of_bounds_ptr_1.rs:LL:CC
|
LL | let x = unsafe { x.offset(5) };
| ^^^^^^^^^^^
= note: inside `main` at $DIR/out_of_bounds_ptr_1.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -1,7 +1,6 @@
//@error-pattern: overflowing in-bounds pointer arithmetic
fn main() {
let v = [0i8; 4];
let x = &v as *const i8;
let x = unsafe { x.offset(isize::MIN) };
let x = unsafe { x.offset(isize::MIN) }; //~ERROR: overflowing in-bounds pointer arithmetic
panic!("this should never print: {:?}", x);
}

View File

@ -1,18 +1,13 @@
error: Undefined Behavior: overflowing in-bounds pointer arithmetic
--> RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC
--> $DIR/out_of_bounds_ptr_2.rs:LL:CC
|
LL | unsafe { intrinsics::offset(self, count) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflowing in-bounds pointer arithmetic
LL | let x = unsafe { x.offset(isize::MIN) };
| ^^^^^^^^^^^^^^^^^^^^ overflowing in-bounds pointer arithmetic
|
= 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 `std::ptr::const_ptr::<impl *const i8>::offset` at RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC
note: inside `main` at $DIR/out_of_bounds_ptr_2.rs:LL:CC
--> $DIR/out_of_bounds_ptr_2.rs:LL:CC
|
LL | let x = unsafe { x.offset(isize::MIN) };
| ^^^^^^^^^^^^^^^^^^^^
= note: inside `main` at $DIR/out_of_bounds_ptr_2.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -1,7 +1,6 @@
//@error-pattern: pointer to 1 byte starting at offset -1 is out-of-bounds
fn main() {
let v = [0i8; 4];
let x = &v as *const i8;
let x = unsafe { x.offset(-1) };
let x = unsafe { x.offset(-1) }; //~ERROR: pointer to 1 byte starting at offset -1 is out-of-bounds
panic!("this should never print: {:?}", x);
}

View File

@ -1,18 +1,13 @@
error: Undefined Behavior: out-of-bounds pointer arithmetic: ALLOC has size 4, so pointer to 1 byte starting at offset -1 is out-of-bounds
--> RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC
--> $DIR/out_of_bounds_ptr_3.rs:LL:CC
|
LL | unsafe { intrinsics::offset(self, count) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: ALLOC has size 4, so pointer to 1 byte starting at offset -1 is out-of-bounds
LL | let x = unsafe { x.offset(-1) };
| ^^^^^^^^^^^^ out-of-bounds pointer arithmetic: ALLOC has size 4, so pointer to 1 byte starting at offset -1 is out-of-bounds
|
= 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 `std::ptr::const_ptr::<impl *const i8>::offset` at RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC
note: inside `main` at $DIR/out_of_bounds_ptr_3.rs:LL:CC
--> $DIR/out_of_bounds_ptr_3.rs:LL:CC
|
LL | let x = unsafe { x.offset(-1) };
| ^^^^^^^^^^^^
= note: inside `main` at $DIR/out_of_bounds_ptr_3.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -1,10 +1,8 @@
#![feature(core_intrinsics)]
use std::intrinsics::*;
#![feature(unchecked_math)]
fn main() {
unsafe {
let _n = unchecked_shr(1i64, 64);
let _n = 1i64.unchecked_shr(64);
//~^ ERROR: overflowing shift by 64 in `unchecked_shr`
}
}

View File

@ -1,8 +1,8 @@
error: Undefined Behavior: overflowing shift by 64 in `unchecked_shr`
--> $DIR/overflowing-unchecked-rsh.rs:LL:CC
|
LL | let _n = unchecked_shr(1i64, 64);
| ^^^^^^^^^^^^^^^^^^^^^^^ overflowing shift by 64 in `unchecked_shr`
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

View File

@ -1,8 +1,9 @@
//@error-pattern: null pointer is a dangling pointer
//@compile-flags: -Zmiri-permissive-provenance
#[rustfmt::skip] // fails with "left behind trailing whitespace"
fn main() {
let x = 0 as *mut i32;
let _x = x.wrapping_offset(8); // ok, this has no inbounds tag
let _x = unsafe { x.offset(0) }; // UB despite offset 0, NULL is never inbounds
//~^ERROR: null pointer is a dangling pointer
}

View File

@ -1,18 +1,13 @@
error: Undefined Behavior: out-of-bounds pointer arithmetic: null pointer is a dangling pointer (it has no provenance)
--> RUSTLIB/core/src/ptr/mut_ptr.rs:LL:CC
--> $DIR/ptr_offset_0_plus_0.rs:LL:CC
|
LL | unsafe { intrinsics::offset(self, count) as *mut T }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: null pointer is a dangling pointer (it has no provenance)
LL | let _x = unsafe { x.offset(0) }; // UB despite offset 0, NULL is never inbounds
| ^^^^^^^^^^^ out-of-bounds pointer arithmetic: null pointer is a dangling pointer (it has no provenance)
|
= 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 `std::ptr::mut_ptr::<impl *mut i32>::offset` at RUSTLIB/core/src/ptr/mut_ptr.rs:LL:CC
note: inside `main` at $DIR/ptr_offset_0_plus_0.rs:LL:CC
--> $DIR/ptr_offset_0_plus_0.rs:LL:CC
|
LL | let _x = unsafe { x.offset(0) }; // UB despite offset 0, NULL is never inbounds
| ^^^^^^^^^^^
= note: inside `main` at $DIR/ptr_offset_0_plus_0.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -1,11 +1,7 @@
#![feature(core_intrinsics)]
use std::intrinsics::ptr_offset_from;
fn main() {
let start_ptr = &4 as *const _ as *const u8;
let length = 10;
let end_ptr = start_ptr.wrapping_add(length);
// Even if the offset is 0, a dangling OOB pointer is not allowed.
unsafe { ptr_offset_from(end_ptr, end_ptr) }; //~ERROR: pointer at offset 10 is out-of-bounds
unsafe { end_ptr.offset_from(end_ptr) }; //~ERROR: pointer at offset 10 is out-of-bounds
}

View File

@ -1,8 +1,8 @@
error: Undefined Behavior: out-of-bounds offset_from: ALLOC has size 4, so pointer at offset 10 is out-of-bounds
--> $DIR/ptr_offset_from_oob.rs:LL:CC
|
LL | unsafe { ptr_offset_from(end_ptr, end_ptr) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds offset_from: ALLOC has size 4, so pointer at offset 10 is out-of-bounds
LL | unsafe { end_ptr.offset_from(end_ptr) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds offset_from: ALLOC has size 4, so pointer at offset 10 is out-of-bounds
|
= 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

View File

@ -1,9 +1,10 @@
//@error-pattern: first pointer has smaller offset than second: 0 < 4
// Preparing for a rustc behavior change that'll happen soon: (FIXME remove this after the next submodule bump succeeded)
//@normalize-stderr-test: "`(ptr_offset_from_unsigned)`" -> "$1"
#![feature(ptr_sub_ptr)]
fn main() {
let arr = [0u8; 8];
let ptr1 = arr.as_ptr();
let ptr2 = ptr1.wrapping_add(4);
let _val = unsafe { ptr1.sub_ptr(ptr2) };
let _val = unsafe { ptr1.sub_ptr(ptr2) }; //~ERROR: first pointer has smaller offset than second: 0 < 4
}

View File

@ -1,18 +1,13 @@
error: Undefined Behavior: ptr_offset_from_unsigned called when first pointer has smaller offset than second: 0 < 4
--> RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC
--> $DIR/ptr_offset_from_unsigned_neg.rs:LL:CC
|
LL | unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ptr_offset_from_unsigned called when first pointer has smaller offset than second: 0 < 4
LL | let _val = unsafe { ptr1.sub_ptr(ptr2) };
| ^^^^^^^^^^^^^^^^^^ ptr_offset_from_unsigned called when first pointer has smaller offset than second: 0 < 4
|
= 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 `std::ptr::const_ptr::<impl *const u8>::sub_ptr` at RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC
note: inside `main` at $DIR/ptr_offset_from_unsigned_neg.rs:LL:CC
--> $DIR/ptr_offset_from_unsigned_neg.rs:LL:CC
|
LL | let _val = unsafe { ptr1.sub_ptr(ptr2) };
| ^^^^^^^^^^^^^^^^^^
= note: inside `main` at $DIR/ptr_offset_from_unsigned_neg.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -1,9 +1,8 @@
//@error-pattern: is a dangling pointer
//@compile-flags: -Zmiri-permissive-provenance
fn main() {
// Can't offset an integer pointer by non-zero offset.
unsafe {
let _val = (1 as *mut u8).offset(1);
let _val = (1 as *mut u8).offset(1); //~ERROR: is a dangling pointer
}
}

View File

@ -1,18 +1,13 @@
error: Undefined Behavior: out-of-bounds pointer arithmetic: 0x1[noalloc] is a dangling pointer (it has no provenance)
--> RUSTLIB/core/src/ptr/mut_ptr.rs:LL:CC
--> $DIR/ptr_offset_int_plus_int.rs:LL:CC
|
LL | unsafe { intrinsics::offset(self, count) as *mut T }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: 0x1[noalloc] is a dangling pointer (it has no provenance)
LL | let _val = (1 as *mut u8).offset(1);
| ^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: 0x1[noalloc] is a dangling pointer (it has no provenance)
|
= 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 `std::ptr::mut_ptr::<impl *mut u8>::offset` at RUSTLIB/core/src/ptr/mut_ptr.rs:LL:CC
note: inside `main` at $DIR/ptr_offset_int_plus_int.rs:LL:CC
--> $DIR/ptr_offset_int_plus_int.rs:LL:CC
|
LL | let _val = (1 as *mut u8).offset(1);
| ^^^^^^^^^^^^^^^^^^^^^^^^
= note: inside `main` at $DIR/ptr_offset_int_plus_int.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -1,10 +1,9 @@
//@error-pattern: is a dangling pointer
//@compile-flags: -Zmiri-permissive-provenance
fn main() {
let ptr = Box::into_raw(Box::new(0u32));
// Can't start with an integer pointer and get to something usable
unsafe {
let _val = (1 as *mut u8).offset(ptr as isize);
let _val = (1 as *mut u8).offset(ptr as isize); //~ERROR: is a dangling pointer
}
}

View File

@ -1,18 +1,13 @@
error: Undefined Behavior: out-of-bounds pointer arithmetic: 0x1[noalloc] is a dangling pointer (it has no provenance)
--> RUSTLIB/core/src/ptr/mut_ptr.rs:LL:CC
--> $DIR/ptr_offset_int_plus_ptr.rs:LL:CC
|
LL | unsafe { intrinsics::offset(self, count) as *mut T }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: 0x1[noalloc] is a dangling pointer (it has no provenance)
LL | let _val = (1 as *mut u8).offset(ptr as isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: 0x1[noalloc] is a dangling pointer (it has no provenance)
|
= 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 `std::ptr::mut_ptr::<impl *mut u8>::offset` at RUSTLIB/core/src/ptr/mut_ptr.rs:LL:CC
note: inside `main` at $DIR/ptr_offset_int_plus_ptr.rs:LL:CC
--> $DIR/ptr_offset_int_plus_ptr.rs:LL:CC
|
LL | let _val = (1 as *mut u8).offset(ptr as isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: inside `main` at $DIR/ptr_offset_int_plus_ptr.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -1,6 +1,5 @@
//@error-pattern: overflowing in-bounds pointer arithmetic
fn main() {
let v = [1i8, 2];
let x = &v[1] as *const i8;
let _val = unsafe { x.offset(isize::MIN) };
let _val = unsafe { x.offset(isize::MIN) }; //~ERROR: overflowing in-bounds pointer arithmetic
}

View File

@ -1,18 +1,13 @@
error: Undefined Behavior: overflowing in-bounds pointer arithmetic
--> RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC
--> $DIR/ptr_offset_overflow.rs:LL:CC
|
LL | unsafe { intrinsics::offset(self, count) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflowing in-bounds pointer arithmetic
LL | let _val = unsafe { x.offset(isize::MIN) };
| ^^^^^^^^^^^^^^^^^^^^ overflowing in-bounds pointer arithmetic
|
= 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 `std::ptr::const_ptr::<impl *const i8>::offset` at RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC
note: inside `main` at $DIR/ptr_offset_overflow.rs:LL:CC
--> $DIR/ptr_offset_overflow.rs:LL:CC
|
LL | let _val = unsafe { x.offset(isize::MIN) };
| ^^^^^^^^^^^^^^^^^^^^
= note: inside `main` at $DIR/ptr_offset_overflow.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -1,7 +1,7 @@
//@error-pattern: pointer at offset 32 is out-of-bounds
#[rustfmt::skip] // fails with "left behind trailing whitespace"
fn main() {
let x = Box::into_raw(Box::new(0u32));
let x = x.wrapping_offset(8); // ok, this has no inbounds tag
let _x = unsafe { x.offset(0) }; // UB despite offset 0, the pointer is not inbounds of the only object it can point to
//~^ERROR: pointer at offset 32 is out-of-bounds
}

View File

@ -1,18 +1,13 @@
error: Undefined Behavior: out-of-bounds pointer arithmetic: ALLOC has size 4, so pointer at offset 32 is out-of-bounds
--> RUSTLIB/core/src/ptr/mut_ptr.rs:LL:CC
--> $DIR/ptr_offset_ptr_plus_0.rs:LL:CC
|
LL | unsafe { intrinsics::offset(self, count) as *mut T }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: ALLOC has size 4, so pointer at offset 32 is out-of-bounds
LL | let _x = unsafe { x.offset(0) }; // UB despite offset 0, the pointer is not inbounds of the only object it can point to
| ^^^^^^^^^^^ out-of-bounds pointer arithmetic: ALLOC has size 4, so pointer at offset 32 is out-of-bounds
|
= 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 `std::ptr::mut_ptr::<impl *mut u32>::offset` at RUSTLIB/core/src/ptr/mut_ptr.rs:LL:CC
note: inside `main` at $DIR/ptr_offset_ptr_plus_0.rs:LL:CC
--> $DIR/ptr_offset_ptr_plus_0.rs:LL:CC
|
LL | let _x = unsafe { x.offset(0) }; // UB despite offset 0, the pointer is not inbounds of the only object it can point to
| ^^^^^^^^^^^
= note: inside `main` at $DIR/ptr_offset_ptr_plus_0.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -1,7 +1,6 @@
#![feature(core_intrinsics)]
#![feature(unchecked_math)]
fn main() {
// MAX overflow
unsafe {
std::intrinsics::unchecked_add(40000u16, 30000); //~ ERROR: overflow executing `unchecked_add`
}
let _val = unsafe { 40000u16.unchecked_add(30000) }; //~ ERROR: overflow executing `unchecked_add`
}

View File

@ -1,8 +1,8 @@
error: Undefined Behavior: overflow executing `unchecked_add`
--> $DIR/unchecked_add1.rs:LL:CC
|
LL | std::intrinsics::unchecked_add(40000u16, 30000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow executing `unchecked_add`
LL | let _val = unsafe { 40000u16.unchecked_add(30000) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow executing `unchecked_add`
|
= 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

View File

@ -1,7 +1,6 @@
#![feature(core_intrinsics)]
#![feature(unchecked_math)]
fn main() {
// MIN overflow
unsafe {
std::intrinsics::unchecked_add(-30000i16, -8000); //~ ERROR: overflow executing `unchecked_add`
}
let _val = unsafe { (-30000i16).unchecked_add(-8000) }; //~ ERROR: overflow executing `unchecked_add`
}

View File

@ -1,8 +1,8 @@
error: Undefined Behavior: overflow executing `unchecked_add`
--> $DIR/unchecked_add2.rs:LL:CC
|
LL | std::intrinsics::unchecked_add(-30000i16, -8000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow executing `unchecked_add`
LL | let _val = unsafe { (-30000i16).unchecked_add(-8000) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow executing `unchecked_add`
|
= 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

View File

@ -1,7 +1,5 @@
#![feature(core_intrinsics)]
#![feature(unchecked_math)]
fn main() {
// MAX overflow
unsafe {
std::intrinsics::unchecked_mul(300u16, 250u16); //~ ERROR: overflow executing `unchecked_mul`
}
let _val = unsafe { 300u16.unchecked_mul(250u16) }; //~ ERROR: overflow executing `unchecked_mul`
}

View File

@ -1,8 +1,8 @@
error: Undefined Behavior: overflow executing `unchecked_mul`
--> $DIR/unchecked_mul1.rs:LL:CC
|
LL | std::intrinsics::unchecked_mul(300u16, 250u16);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow executing `unchecked_mul`
LL | let _val = unsafe { 300u16.unchecked_mul(250u16) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow executing `unchecked_mul`
|
= 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

View File

@ -1,7 +1,5 @@
#![feature(core_intrinsics)]
#![feature(unchecked_math)]
fn main() {
// MIN overflow
unsafe {
std::intrinsics::unchecked_mul(1_000_000_000i32, -4); //~ ERROR: overflow executing `unchecked_mul`
}
let _val = unsafe { 1_000_000_000i32.unchecked_mul(-4) }; //~ ERROR: overflow executing `unchecked_mul`
}

View File

@ -1,8 +1,8 @@
error: Undefined Behavior: overflow executing `unchecked_mul`
--> $DIR/unchecked_mul2.rs:LL:CC
|
LL | std::intrinsics::unchecked_mul(1_000_000_000i32, -4);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow executing `unchecked_mul`
LL | let _val = unsafe { 1_000_000_000i32.unchecked_mul(-4) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow executing `unchecked_mul`
|
= 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

View File

@ -1,7 +1,5 @@
#![feature(core_intrinsics)]
#![feature(unchecked_math)]
fn main() {
// MIN overflow
unsafe {
std::intrinsics::unchecked_sub(14u32, 22); //~ ERROR: overflow executing `unchecked_sub`
}
let _val = unsafe { 14u32.unchecked_sub(22) }; //~ ERROR: overflow executing `unchecked_sub`
}

View File

@ -1,8 +1,8 @@
error: Undefined Behavior: overflow executing `unchecked_sub`
--> $DIR/unchecked_sub1.rs:LL:CC
|
LL | std::intrinsics::unchecked_sub(14u32, 22);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow executing `unchecked_sub`
LL | let _val = unsafe { 14u32.unchecked_sub(22) };
| ^^^^^^^^^^^^^^^^^^^^^^^ overflow executing `unchecked_sub`
|
= 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

View File

@ -1,7 +1,5 @@
#![feature(core_intrinsics)]
#![feature(unchecked_math)]
fn main() {
// MAX overflow
unsafe {
std::intrinsics::unchecked_sub(30000i16, -7000); //~ ERROR: overflow executing `unchecked_sub`
}
let _val = unsafe { 30000i16.unchecked_sub(-7000) }; //~ ERROR: overflow executing `unchecked_sub`
}

View File

@ -1,8 +1,8 @@
error: Undefined Behavior: overflow executing `unchecked_sub`
--> $DIR/unchecked_sub2.rs:LL:CC
|
LL | std::intrinsics::unchecked_sub(30000i16, -7000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow executing `unchecked_sub`
LL | let _val = unsafe { 30000i16.unchecked_sub(-7000) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow executing `unchecked_sub`
|
= 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

View File

@ -2,8 +2,6 @@
// Make sure we find these even with many checks disabled.
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
//@error-pattern: enum value has invalid tag
use std::mem;
#[repr(C)]
@ -16,5 +14,5 @@ pub enum Foo {
fn main() {
let f = unsafe { std::mem::transmute::<i32, Foo>(42) };
let _val = mem::discriminant(&f);
let _val = mem::discriminant(&f); //~ERROR: enum value has invalid tag
}

View File

@ -1,18 +1,13 @@
error: Undefined Behavior: enum value has invalid tag: $HEX
--> RUSTLIB/core/src/mem/mod.rs:LL:CC
--> $DIR/invalid_enum_tag.rs:LL:CC
|
LL | Discriminant(intrinsics::discriminant_value(v))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ enum value has invalid tag: $HEX
LL | let _val = mem::discriminant(&f);
| ^^^^^^^^^^^^^^^^^^^^^ enum value has invalid tag: $HEX
|
= 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 `std::mem::discriminant::<Foo>` at RUSTLIB/core/src/mem/mod.rs:LL:CC
note: inside `main` at $DIR/invalid_enum_tag.rs:LL:CC
--> $DIR/invalid_enum_tag.rs:LL:CC
|
LL | let _val = mem::discriminant(&f);
| ^^^^^^^^^^^^^^^^^^^^^
= note: inside `main` at $DIR/invalid_enum_tag.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -1,5 +1,4 @@
//@compile-flags: -Zmiri-strict-provenance
//@error-pattern: is a dangling pointer
#![feature(strict_provenance)]
fn main() {
@ -7,5 +6,5 @@ fn main() {
let ptr = &x as *const _ as *const u8;
let roundtrip = std::ptr::invalid::<u8>(ptr as usize);
// Not even offsetting this is allowed.
let _ = unsafe { roundtrip.offset(1) };
let _ = unsafe { roundtrip.offset(1) }; //~ERROR: is a dangling pointer
}

View File

@ -1,18 +1,13 @@
error: Undefined Behavior: out-of-bounds pointer arithmetic: $HEX[noalloc] is a dangling pointer (it has no provenance)
--> RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC
--> $DIR/ptr_invalid_offset.rs:LL:CC
|
LL | unsafe { intrinsics::offset(self, count) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: $HEX[noalloc] is a dangling pointer (it has no provenance)
LL | let _ = unsafe { roundtrip.offset(1) };
| ^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer arithmetic: $HEX[noalloc] is a dangling pointer (it has no provenance)
|
= 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 `std::ptr::const_ptr::<impl *const u8>::offset` at RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC
note: inside `main` at $DIR/ptr_invalid_offset.rs:LL:CC
--> $DIR/ptr_invalid_offset.rs:LL:CC
|
LL | let _ = unsafe { roundtrip.offset(1) };
| ^^^^^^^^^^^^^^^^^^^
= note: inside `main` at $DIR/ptr_invalid_offset.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -1,6 +1,5 @@
//@ignore-target-windows: Concurrency on Windows is not supported yet.
//@compile-flags: -Zmiri-ignore-leaks
//@error-pattern: unreachable
// https://plv.mpi-sws.org/scfix/paper.pdf
// 2.2 Second Problem: SC Fences are Too Weak
@ -77,7 +76,7 @@ fn test_cpp20_rwc_syncs() {
if (b, c) == (0, 0) {
// This *should* be unreachable, but Miri will reach it.
unsafe {
std::hint::unreachable_unchecked();
std::hint::unreachable_unchecked(); //~ERROR: unreachable
}
}
}

View File

@ -1,18 +1,13 @@
error: Undefined Behavior: entering unreachable code
--> RUSTLIB/core/src/hint.rs:LL:CC
--> $DIR/cpp20_rwc_syncs.rs:LL:CC
|
LL | unsafe { intrinsics::unreachable() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^ entering unreachable code
LL | std::hint::unreachable_unchecked();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entering unreachable code
|
= 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 `std::hint::unreachable_unchecked` at RUSTLIB/core/src/hint.rs:LL:CC
note: inside `test_cpp20_rwc_syncs` at $DIR/cpp20_rwc_syncs.rs:LL:CC
--> $DIR/cpp20_rwc_syncs.rs:LL:CC
|
LL | std::hint::unreachable_unchecked();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: inside `test_cpp20_rwc_syncs` at $DIR/cpp20_rwc_syncs.rs:LL:CC
note: inside `main` at $DIR/cpp20_rwc_syncs.rs:LL:CC
--> $DIR/cpp20_rwc_syncs.rs:LL:CC
|

View File

@ -1,4 +1,3 @@
//@error-pattern: entering unreachable code
fn main() {
unsafe { std::hint::unreachable_unchecked() }
unsafe { std::hint::unreachable_unchecked() } //~ERROR: entering unreachable code
}

View File

@ -1,18 +1,13 @@
error: Undefined Behavior: entering unreachable code
--> RUSTLIB/core/src/hint.rs:LL:CC
--> $DIR/unreachable.rs:LL:CC
|
LL | unsafe { intrinsics::unreachable() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^ entering unreachable code
LL | unsafe { std::hint::unreachable_unchecked() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entering unreachable code
|
= 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 `std::hint::unreachable_unchecked` at RUSTLIB/core/src/hint.rs:LL:CC
note: inside `main` at $DIR/unreachable.rs:LL:CC
--> $DIR/unreachable.rs:LL:CC
|
LL | unsafe { std::hint::unreachable_unchecked() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: inside `main` at $DIR/unreachable.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -4,6 +4,7 @@
#![feature(core_intrinsics)]
use std::ptr;
use std::sync::atomic::AtomicU32;
use std::sync::atomic::Ordering::*;
use std::thread::spawn;
@ -30,7 +31,7 @@ pub fn main() {
let x_ptr = x as *const AtomicU32 as *const u32;
let x_split = split_u32_ptr(x_ptr);
unsafe {
let hi = &(*x_split)[0] as *const u16;
let hi = ptr::addr_of!((*x_split)[0]);
std::intrinsics::atomic_load_relaxed(hi); //~ ERROR: imperfectly overlapping
}
});