-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
64 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//@ run-fail | ||
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes | ||
//@ error-pattern: unsafe precondition(s) violated: ptr::copy_nonoverlapping | ||
//@ ignore-debug | ||
//@ revisions: null_src null_dst misaligned_src misaligned_dst overlapping | ||
|
||
use std::ptr; | ||
|
||
fn main() { | ||
let src = [0u16; 3]; | ||
let mut dst = [0u16; 3]; | ||
let src = src.as_ptr(); | ||
let dst = dst.as_mut_ptr(); | ||
unsafe { | ||
#[cfg(null_src)] | ||
ptr::copy_nonoverlapping(ptr::null(), dst, 1); | ||
#[cfg(null_dst)] | ||
ptr::copy_nonoverlapping(src, ptr::null_mut(), 1); | ||
#[cfg(misaligned_src)] | ||
ptr::copy_nonoverlapping(src.byte_add(1), dst, 1); | ||
#[cfg(misaligned_dst)] | ||
ptr::copy_nonoverlapping(src, dst.byte_add(1), 1); | ||
#[cfg(overlapping)] | ||
ptr::copy_nonoverlapping(dst, dst.add(1), 2); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
tests/ui/precondition-checks/nonoverlapping-overlapping.rs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//@ run-fail | ||
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes | ||
//@ error-pattern: unsafe precondition(s) violated: slice::from_raw_parts_mut | ||
//@ ignore-debug | ||
//@ revisions: null misaligned toolarge | ||
|
||
fn main() { | ||
unsafe { | ||
#[cfg(null)] | ||
let _s: &mut [u8] = std::slice::from_raw_parts_mut(std::ptr::null_mut(), 0); | ||
#[cfg(misaligned)] | ||
let _s: &mut [u16] = std::slice::from_raw_parts_mut(1usize as *mut u16, 0); | ||
#[cfg(toolarge)] | ||
let _s: &mut [u16] = std::slice::from_raw_parts_mut(2usize as *mut u16, isize::MAX as usize); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//@ run-fail | ||
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes | ||
//@ error-pattern: unsafe precondition(s) violated: slice::from_raw_parts | ||
//@ ignore-debug | ||
//@ revisions: null misaligned toolarge | ||
|
||
fn main() { | ||
unsafe { | ||
#[cfg(null)] | ||
let _s: &[u8] = std::slice::from_raw_parts(std::ptr::null(), 0); | ||
#[cfg(misaligned)] | ||
let _s: &[u16] = std::slice::from_raw_parts(1usize as *const u16, 0); | ||
#[cfg(toolarge)] | ||
let _s: &[u16] = std::slice::from_raw_parts(2usize as *const u16, isize::MAX as usize); | ||
} | ||
} |