Skip to content

Commit 19c585e

Browse files
committed
Add more precondition check tests
1 parent 8413ddc commit 19c585e

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ run-fail
2+
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3+
//@ error-pattern: unsafe precondition(s) violated: ptr::copy_nonoverlapping
4+
//@ ignore-debug
5+
6+
fn main() {
7+
let src: [u16; 2] = [0, 0];
8+
let mut dst: [u16; 2] = [0, 0];
9+
let src = src.as_ptr();
10+
let dst = dst.as_mut_ptr();
11+
unsafe {
12+
std::ptr::copy_nonoverlapping(src.byte_add(1), dst, 1);
13+
}
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ run-pass
2+
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3+
4+
fn main() {
5+
unsafe {
6+
std::ptr::copy_nonoverlapping(std::ptr::null::<u8>(), std::ptr::null_mut(), 0);
7+
}
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ run-fail
2+
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3+
//@ error-pattern: unsafe precondition(s) violated: ptr::copy_nonoverlapping
4+
//@ ignore-debug
5+
6+
fn main() {
7+
let mut buf: [u8; 3] = [0, 1, 2];
8+
let ptr = buf.as_mut_ptr();
9+
unsafe {
10+
std::ptr::copy_nonoverlapping(ptr, ptr.add(1), 2);
11+
}
12+
}

0 commit comments

Comments
 (0)