Skip to content

Commit 1238681

Browse files
authored
Adjust sized hierarchy for Kani's memory predicates (#4193)
As fix-up to 96eb502: several of Kani's memory predicates do not actually require a (dynamically) sized type. Relaxing the requirement to `PointeeSized` permits use of those memory predicates from contracts for NonNull, const and mut pointers. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent a9e14fe commit 1238681

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

library/kani_core/src/mem.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
macro_rules! kani_mem {
1313
($core:tt) => {
1414
use super::kani_intrinsic;
15-
use $core::marker::MetaSized;
15+
use $core::marker::{MetaSized, PointeeSized};
1616
use $core::ptr::{DynMetadata, NonNull, Pointee};
1717

1818
/// Check if the pointer is valid for write access according to [crate::mem] conditions 1, 2
@@ -117,12 +117,12 @@ macro_rules! kani_mem {
117117
reason = "experimental memory predicate API"
118118
)]
119119
#[allow(clippy::not_unsafe_ptr_arg_deref)]
120-
pub fn same_allocation<T: MetaSized>(ptr1: *const T, ptr2: *const T) -> bool {
120+
pub fn same_allocation<T: PointeeSized>(ptr1: *const T, ptr2: *const T) -> bool {
121121
same_allocation_internal(ptr1, ptr2)
122122
}
123123

124124
#[allow(clippy::not_unsafe_ptr_arg_deref)]
125-
pub(super) fn same_allocation_internal<T: MetaSized>(
125+
pub(super) fn same_allocation_internal<T: PointeeSized>(
126126
ptr1: *const T,
127127
ptr2: *const T,
128128
) -> bool {
@@ -241,19 +241,19 @@ macro_rules! kani_mem {
241241
/// - Users have to ensure that the pointed to memory is allocated.
242242
#[kanitool::fn_marker = "ValidValueIntrinsic"]
243243
#[inline(never)]
244-
unsafe fn has_valid_value<T: MetaSized>(_ptr: *const T) -> bool {
244+
unsafe fn has_valid_value<T: PointeeSized>(_ptr: *const T) -> bool {
245245
kani_intrinsic()
246246
}
247247

248248
/// Check whether `len * size_of::<T>()` bytes are initialized starting from `ptr`.
249249
#[kanitool::fn_marker = "IsInitializedIntrinsic"]
250250
#[inline(never)]
251-
pub(crate) fn is_initialized<T: MetaSized>(_ptr: *const T) -> bool {
251+
pub(crate) fn is_initialized<T: PointeeSized>(_ptr: *const T) -> bool {
252252
kani_intrinsic()
253253
}
254254

255255
/// A helper to assert `is_initialized` to use it as a part of other predicates.
256-
fn assert_is_initialized<T: MetaSized>(ptr: *const T) -> bool {
256+
fn assert_is_initialized<T: PointeeSized>(ptr: *const T) -> bool {
257257
super::internal::check(
258258
is_initialized(ptr),
259259
"Undefined Behavior: Reading from an uninitialized pointer",
@@ -281,7 +281,7 @@ macro_rules! kani_mem {
281281
#[doc(hidden)]
282282
#[kanitool::fn_marker = "PointerObjectHook"]
283283
#[inline(never)]
284-
pub(crate) fn pointer_object<T: MetaSized>(_ptr: *const T) -> usize {
284+
pub(crate) fn pointer_object<T: PointeeSized>(_ptr: *const T) -> usize {
285285
kani_intrinsic()
286286
}
287287

@@ -294,7 +294,7 @@ macro_rules! kani_mem {
294294
)]
295295
#[kanitool::fn_marker = "PointerOffsetHook"]
296296
#[inline(never)]
297-
pub fn pointer_offset<T: MetaSized>(_ptr: *const T) -> usize {
297+
pub fn pointer_offset<T: PointeeSized>(_ptr: *const T) -> usize {
298298
kani_intrinsic()
299299
}
300300
};

0 commit comments

Comments
 (0)