miri: add test for overlapping typed_swap
This commit is contained in:
parent
6de3a2e3a9
commit
00dfa3ba2d
3 changed files with 29 additions and 1 deletions
|
@ -649,7 +649,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
let kind = MemoryKind::Stack;
|
||||
let temp = self.allocate(left.layout, kind)?;
|
||||
self.copy_op(&left, &temp)?;
|
||||
self.copy_op(&right, &left)?;
|
||||
self.copy_op(&right, &left)?; // this checks that they are non-overlapping
|
||||
self.copy_op(&temp, &right)?;
|
||||
self.deallocate_ptr(temp.ptr(), None, kind)?;
|
||||
interp_ok(())
|
||||
|
|
13
src/tools/miri/tests/fail/intrinsics/typed-swap-overlap.rs
Normal file
13
src/tools/miri/tests/fail/intrinsics/typed-swap-overlap.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
#![feature(core_intrinsics)]
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
use std::intrinsics::typed_swap;
|
||||
use std::ptr::addr_of_mut;
|
||||
|
||||
fn main() {
|
||||
let mut a = [0_u8; 100];
|
||||
unsafe {
|
||||
let a = addr_of_mut!(a);
|
||||
typed_swap(a, a); //~ERROR: called on overlapping ranges
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
error: Undefined Behavior: `copy_nonoverlapping` called on overlapping ranges
|
||||
--> tests/fail/intrinsics/typed-swap-overlap.rs:LL:CC
|
||||
|
|
||||
LL | typed_swap(a, a);
|
||||
| ^^^^^^^^^^^^^^^^ `copy_nonoverlapping` called on overlapping ranges
|
||||
|
|
||||
= 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 tests/fail/intrinsics/typed-swap-overlap.rs:LL:CC
|
||||
|
||||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue