Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion library/kani_core/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ macro_rules! kani_mem {
///
/// This function aligns with Rust's memory safety requirements, which restrict valid allocations
/// to sizes no larger than `isize::MAX`.
fn is_inbounds<T: ?Sized>(ptr: *const T) -> bool {
#[crate::kani::unstable_feature(
feature = "mem-predicates",
issue = 3946,
reason = "experimental memory predicate API"
)]
pub fn is_inbounds<T: ?Sized>(ptr: *const T) -> bool {
// If size overflows, then pointer cannot be inbounds.
let Some(sz) = checked_size_of_raw(ptr) else { return false };
if sz == 0 {
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/MemPredicates/ptr_size_validity.expected
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Complete - 1 successfully verified harnesses, 0 failures, 1 total.
Complete - 2 successfully verified harnesses, 0 failures, 2 total.
10 changes: 10 additions & 0 deletions tests/expected/MemPredicates/ptr_size_validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ extern crate kani;
mod size {
use super::*;

#[kani::proof]
fn verify_is_inbounds() {
let val = 42u8;
let ptr = &val as *const u8;
assert!(kani::mem::is_inbounds(ptr));

let null_ptr: *const u8 = core::ptr::null();
assert!(!kani::mem::is_inbounds(null_ptr));
}

#[kani::proof]
fn verify_checked_size_of_raw_exceeds_isize_max() {
let len_exceeding_isize_max = (isize::MAX as usize) + 1;
Expand Down
Loading