You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//! This module contains a dummy implementation of a slice iterator.//!//! It shows how computing pointer offset by using integer arithmetic + casting does not yield//! the same result as operating on pointer directly.#![feature(core_intrinsics)]use std::marker::PhantomData;#[kani::proof]fncheck_addr_offset(){let array = [0,1,2];let slice = &array;letmut iter = MyIter::new(slice);let first = iter.next().unwrap();let second = iter.next().unwrap();let third = iter.next().unwrap();assert!(iter.next().is_none());assert_eq!(*first,0);assert_eq!(*second,1);assert_eq!(*third,2);}#[kani::proof]#[kani::stub(addr_offset, ptr_offset)]fncheck_ptr_offset(){check_addr_offset();}pubstructMyIter<'a>{ptr:*consti8,end:*consti8,phantom_data:PhantomData<&'a i8>,}impl<'a>MyIter<'a>{pubfnnew(slice:&[i8]) -> Self{MyIter{ptr: slice.as_ptr(),end:addr_offset(slice.as_ptr(), slice.len()),phantom_data:PhantomData}}pubfnnext(&mutself) -> Option<&'a i8>{ifself.ptr == self.end{None}else{let result = unsafe{&*self.ptr};self.ptr = addr_offset(self.ptr,1);Some(result)}}}/// Version of offset that converts pointer to usize, performs the offset, then cast the result.fnaddr_offset(ptr:*consti8,byte_offset:usize) -> *consti8{
std::intrinsics::wrapping_add(ptr asusize, byte_offset)as*consti8}/// Version that does a pointer offset directly via intrinsic.fnptr_offset(ptr:*consti8,byte_offset:usize) -> *consti8{unsafe{ std::intrinsics::arith_offset(ptr, byte_offset asisize)}}
using the following command line invocation:
kani dummy_iter.rs
with Kani version: 0.56.0
I expected to see this happen: Verification to succeed.
Instead, this happened: The harness where we compute offset using the pointer address fails, while the one doing the offset in the pointer directly succeeds.
Note that for some reason, the second element is set to a non-deterministic value, while the third element is correct. I enabled -Z uninit-checks as well as --extra-pointer-checks, and none of them detected any other issue.
I tried this code:
using the following command line invocation:
with Kani version: 0.56.0
I expected to see this happen: Verification to succeed.
Instead, this happened: The harness where we compute offset using the pointer address fails, while the one doing the offset in the pointer directly succeeds.
Note that for some reason, the second element is set to a non-deterministic value, while the third element is correct. I enabled
-Z uninit-checks
as well as--extra-pointer-checks
, and none of them detected any other issue.This issue is a blocker for #90.
The text was updated successfully, but these errors were encountered: