Skip to content

Commit

Permalink
Add harness for Alignment::new_unchecked
Browse files Browse the repository at this point in the history
In model-checking#33 a contract was added to `Alignment::new_unchecked`, but its
verification was only implicit through `Layout`, and may be affected by
future changes to the contract that was added to `Layout`. This commit
remedies this by adding a separate harness just for `Alignment`.
  • Loading branch information
tautschnig committed Jul 23, 2024
1 parent 4f4d032 commit 44824f1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions library/core/src/ptr/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,20 @@ enum AlignmentEnum {
_Align1Shl62 = 1 << 62,
_Align1Shl63 = 1 << 63,
}

#[cfg(kani)]
#[unstable(feature="kani", issue="none")]
mod verify {
use super::*;

#[kani::proof_for_contract(Alignment::new_unchecked)]
pub fn check_new_unchecked() {
let a = kani::any::<usize>();

unsafe {
let alignment = Alignment::new_unchecked(a);
assert_eq!(alignment.as_usize(), a);
assert!(a.is_power_of_two());
}
}
}

0 comments on commit 44824f1

Please sign in to comment.