Skip to content

Commit

Permalink
Reorganize a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Oct 8, 2024
1 parent 06183c7 commit 7188e5f
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 54 deletions.
26 changes: 26 additions & 0 deletions tests/ui/precondition-checks/copy-nonoverlapping.rs
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
//@ error-pattern: unsafe precondition(s) violated: Layout::from_size_align_unchecked
//@ ignore-debug
//@ revisions: toolarge badalign
//@[toolarge] compile-flags: --cfg toolarge
//@[badalign] compile-flags: --cfg badalign

fn main() {
unsafe {
#[cfg(toolarge)]
std::alloc::Layout::from_size_align_unchecked(isize::MAX as usize, 2);
#[cfg(badalign)]
std::alloc::Layout::from_size_align_unchecked(1, 3);
}
}
10 changes: 0 additions & 10 deletions tests/ui/precondition-checks/misaligned-slice.rs

This file was deleted.

File renamed without changes.
14 changes: 0 additions & 14 deletions tests/ui/precondition-checks/nonoverlapping-misaligned.rs

This file was deleted.

8 changes: 0 additions & 8 deletions tests/ui/precondition-checks/nonoverlapping-null.rs

This file was deleted.

12 changes: 0 additions & 12 deletions tests/ui/precondition-checks/nonoverlapping-overlapping.rs

This file was deleted.

10 changes: 0 additions & 10 deletions tests/ui/precondition-checks/null-slice.rs

This file was deleted.

16 changes: 16 additions & 0 deletions tests/ui/precondition-checks/slice-from-raw-parts-mut.rs
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);

Check failure on line 14 in tests/ui/precondition-checks/slice-from-raw-parts-mut.rs

View workflow job for this annotation

GitHub Actions / PR - mingw-check-tidy

line longer than 100 chars
}
}
16 changes: 16 additions & 0 deletions tests/ui/precondition-checks/slice-from-raw-parts.rs
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);
}
}

0 comments on commit 7188e5f

Please sign in to comment.