Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update and bless tests for copy intrinsic
  • Loading branch information
usbalbin committed Jun 27, 2021
commit c0125532ead50d3ae4bc4846e7fbdb23da6d8531
13 changes: 4 additions & 9 deletions src/test/ui/consts/copy-intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,27 @@ const COPY_OOB_1: () = unsafe {
let mut x = 0i32;
let dangle = (&mut x as *mut i32).wrapping_add(10);
// Even if the first ptr is an int ptr and this is a ZST copy, we should detect dangling 2nd ptrs.
copy_nonoverlapping(0x100 as *const i32, dangle, 0); //~ ERROR any use of this value will cause an error
//~| memory access failed: pointer must be in-bounds
//~| previously accepted
copy_nonoverlapping(0x100 as *const i32, dangle, 0); //~ evaluation of constant value failed [E0080]
};
const COPY_OOB_2: () = unsafe {
let x = 0i32;
let dangle = (&x as *const i32).wrapping_add(10);
// Even if the second ptr is an int ptr and this is a ZST copy, we should detect dangling 1st ptrs.
copy_nonoverlapping(dangle, 0x100 as *mut i32, 0); //~ ERROR any use of this value will cause an error
copy_nonoverlapping(dangle, 0x100 as *mut i32, 0); //~ evaluation of constant value failed [E0080]
//~| memory access failed: pointer must be in-bounds
//~| previously accepted
};

const COPY_SIZE_OVERFLOW: () = unsafe {
let x = 0;
let mut y = 0;
copy(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1)); //~ ERROR any use of this value will cause an error
copy(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1)); //~ evaluation of constant value failed [E0080]
//~| overflow computing total size of `copy`
//~| previously accepted
};
const COPY_NONOVERLAPPING_SIZE_OVERFLOW: () = unsafe {
let x = 0;
let mut y = 0;
copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1)); //~ ERROR any use of this value will cause an error
copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1)); //~ evaluation of constant value failed [E0080]
//~| overflow computing total size of `copy_nonoverlapping`
//~| previously accepted
};

fn main() {
Expand Down
74 changes: 16 additions & 58 deletions src/test/ui/consts/copy-intrinsic.stderr
Original file line number Diff line number Diff line change
@@ -1,69 +1,27 @@
error: any use of this value will cause an error
error[E0080]: evaluation of constant value failed
--> $DIR/copy-intrinsic.rs:27:5
|
LL | / const COPY_OOB_1: () = unsafe {
LL | | let mut x = 0i32;
LL | | let dangle = (&mut x as *mut i32).wrapping_add(10);
LL | | // Even if the first ptr is an int ptr and this is a ZST copy, we should detect dangling 2nd ptrs.
LL | | copy_nonoverlapping(0x100 as *const i32, dangle, 0);
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc4 which has size 4
LL | |
LL | |
LL | | };
| |__-
|
= note: `#[deny(const_err)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
LL | copy_nonoverlapping(0x100 as *const i32, dangle, 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc4 which has size 4

error: any use of this value will cause an error
--> $DIR/copy-intrinsic.rs:35:5
|
LL | / const COPY_OOB_2: () = unsafe {
LL | | let x = 0i32;
LL | | let dangle = (&x as *const i32).wrapping_add(10);
LL | | // Even if the second ptr is an int ptr and this is a ZST copy, we should detect dangling 1st ptrs.
LL | | copy_nonoverlapping(dangle, 0x100 as *mut i32, 0);
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc6 which has size 4
LL | |
LL | |
LL | | };
| |__-
error[E0080]: evaluation of constant value failed
--> $DIR/copy-intrinsic.rs:33:5
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
LL | copy_nonoverlapping(dangle, 0x100 as *mut i32, 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc6 which has size 4

error: any use of this value will cause an error
--> $DIR/copy-intrinsic.rs:43:5
error[E0080]: evaluation of constant value failed
--> $DIR/copy-intrinsic.rs:40:5
|
LL | / const COPY_SIZE_OVERFLOW: () = unsafe {
LL | | let x = 0;
LL | | let mut y = 0;
LL | | copy(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy`
LL | |
LL | |
LL | | };
| |__-
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
LL | copy(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy`

error: any use of this value will cause an error
--> $DIR/copy-intrinsic.rs:50:5
|
LL | / const COPY_NONOVERLAPPING_SIZE_OVERFLOW: () = unsafe {
LL | | let x = 0;
LL | | let mut y = 0;
LL | | copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy_nonoverlapping`
LL | |
LL | |
LL | | };
| |__-
error[E0080]: evaluation of constant value failed
--> $DIR/copy-intrinsic.rs:46:5
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
LL | copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy_nonoverlapping`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0080`.