Skip to content

Commit

Permalink
Add assumptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tautschnig committed Aug 9, 2024
1 parent e331419 commit 45505ed
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions library/core/src/alloc/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ mod verify {
pub fn check_size() {
let s = kani::any::<usize>();
let a = kani::any::<usize>();
kani::assume(Layout::from_size_align(s, a).is_ok());
unsafe {
let layout = Layout::from_size_align_unchecked(s, a);
assert_eq!(layout.size(), s);
Expand Down Expand Up @@ -605,6 +606,7 @@ mod verify {
pub fn check_dangling() {
let s = kani::any::<usize>();
let a = kani::any::<usize>();
kani::assume(Layout::from_size_align(s, a).is_ok());
unsafe {
let layout = Layout::from_size_align_unchecked(s, a);
let _ = layout.dangling();
Expand All @@ -616,6 +618,7 @@ mod verify {
pub fn check_align_to() {
let s = kani::any::<usize>();
let a = kani::any::<usize>();
kani::assume(Layout::from_size_align(s, a).is_ok());
unsafe {
let layout = Layout::from_size_align_unchecked(s, a);
let a2 = kani::any::<usize>();
Expand All @@ -628,6 +631,7 @@ mod verify {
pub fn check_padding_needed_for() {
let s = kani::any::<usize>();
let a = kani::any::<usize>();
kani::assume(Layout::from_size_align(s, a).is_ok());
unsafe {
let layout = Layout::from_size_align_unchecked(s, a);
let a2 = kani::any::<usize>();
Expand All @@ -642,6 +646,7 @@ mod verify {
pub fn check_pad_to_align() {
let s = kani::any::<usize>();
let a = kani::any::<usize>();
kani::assume(Layout::from_size_align(s, a).is_ok());
unsafe {
let layout = Layout::from_size_align_unchecked(s, a);
let _ = layout.pad_to_align();
Expand All @@ -653,6 +658,7 @@ mod verify {
pub fn check_repeat() {
let s = kani::any::<usize>();
let a = kani::any::<usize>();
kani::assume(Layout::from_size_align(s, a).is_ok());
unsafe {
let layout = Layout::from_size_align_unchecked(s, a);
let n = kani::any::<usize>();
Expand All @@ -665,10 +671,12 @@ mod verify {
pub fn check_extend() {
let s = kani::any::<usize>();
let a = kani::any::<usize>();
kani::assume(Layout::from_size_align(s, a).is_ok());
unsafe {
let layout = Layout::from_size_align_unchecked(s, a);
let s2 = kani::any::<usize>();
let a2 = kani::any::<usize>();
kani::assume(Layout::from_size_align(s2, a2).is_ok());
let layout2 = Layout::from_size_align_unchecked(s2, a2);
let _ = layout.extend(layout2);
}
Expand All @@ -679,6 +687,7 @@ mod verify {
pub fn check_repeat_packed() {
let s = kani::any::<usize>();
let a = kani::any::<usize>();
kani::assume(Layout::from_size_align(s, a).is_ok());
unsafe {
let layout = Layout::from_size_align_unchecked(s, a);
let n = kani::any::<usize>();
Expand All @@ -691,10 +700,12 @@ mod verify {
pub fn check_extend_packed() {
let s = kani::any::<usize>();
let a = kani::any::<usize>();
kani::assume(Layout::from_size_align(s, a).is_ok());
unsafe {
let layout = Layout::from_size_align_unchecked(s, a);
let s2 = kani::any::<usize>();
let a2 = kani::any::<usize>();
kani::assume(Layout::from_size_align(s2, a2).is_ok());
let layout2 = Layout::from_size_align_unchecked(s2, a2);
let _ = layout.extend_packed(layout2);
}
Expand Down

0 comments on commit 45505ed

Please sign in to comment.