@@ -2763,6 +2763,7 @@ mod verify {
27632763 trait TestTrait { }
27642764
27652765 // Struct used exclusively for implementing proofs for contracts for `dyn Trait` type.
2766+ #[ cfg_attr( kani, derive( kani:: Arbitrary ) ) ]
27662767 struct TestStruct {
27672768 value : i64 ,
27682769 }
@@ -2775,7 +2776,7 @@ mod verify {
27752776 /// - `$proof_name`: Specifies the name of the generated proof for contract.
27762777 macro_rules! gen_mut_byte_arith_harness_for_dyn {
27772778 ( byte_offset, $proof_name: ident) => {
2778- //tracking issue: https://github.com/model-checking/kani/issues/3763
2779+ // tracking issue: https://github.com/model-checking/kani/issues/3763
27792780 // Workaround: Directly verifying the method `<*mut dyn TestTrait>::byte_offset`
27802781 // causes a compilation error. As a workaround, the proof is annotated with the
27812782 // underlying struct type instead.
@@ -2793,7 +2794,7 @@ mod verify {
27932794 }
27942795 } ;
27952796 ( $fn_name: ident, $proof_name: ident) => {
2796- //tracking issue: https://github.com/model-checking/kani/issues/3763
2797+ // tracking issue: https://github.com/model-checking/kani/issues/3763
27972798 // Workaround: Directly verifying the method `<*mut dyn TestTrait>::$fn_name`
27982799 // causes a compilation error. As a workaround, the proof is annotated with the
27992800 // underlying struct type instead.
@@ -3013,4 +3014,30 @@ mod verify {
30133014 generate_mut_byte_offset_from_slice_harness ! ( i64 , check_mut_byte_offset_from_i64_slice) ;
30143015 generate_mut_byte_offset_from_slice_harness ! ( i128 , check_mut_byte_offset_from_i128_slice) ;
30153016 generate_mut_byte_offset_from_slice_harness ! ( isize , check_mut_byte_offset_from_isize_slice) ;
3017+
3018+ // tracking issue: https://github.com/model-checking/kani/issues/3763
3019+ // Workaround: Directly verifying the method `<*mut dyn TestTrait>::byte_offset_from`
3020+ // causes a compilation error. As a workaround, the proof is annotated with the
3021+ // underlying struct type instead.
3022+ #[ kani:: proof_for_contract( <* mut TestStruct >:: byte_offset_from) ]
3023+ pub fn check_mut_byte_offset_from_dyn ( ) {
3024+ const gen_size: usize = mem:: size_of :: < TestStruct > ( ) ;
3025+ // Since the pointer generator cannot directly create pointers to `dyn Trait`,
3026+ // we first generate a pointer to the underlying struct and then cast it to a `dyn Trait` pointer.
3027+ let mut generator_caller = PointerGenerator :: < gen_size > :: new ( ) ;
3028+ let mut generator_input = PointerGenerator :: < gen_size > :: new ( ) ;
3029+ let ptr_caller: * mut TestStruct = generator_caller. any_in_bounds ( ) . ptr ;
3030+ let ptr_input: * mut TestStruct = if kani:: any ( ) {
3031+ generator_caller. any_alloc_status ( ) . ptr
3032+ } else {
3033+ generator_input. any_alloc_status ( ) . ptr
3034+ } ;
3035+
3036+ let ptr_caller = ptr_caller as * mut dyn TestTrait ;
3037+ let ptr_input = ptr_input as * mut dyn TestTrait ;
3038+
3039+ unsafe {
3040+ ptr_caller. byte_offset_from ( ptr_input) ;
3041+ }
3042+ }
30163043}
0 commit comments