@@ -2763,6 +2763,7 @@ mod verify {
2763
2763
trait TestTrait { }
2764
2764
2765
2765
// Struct used exclusively for implementing proofs for contracts for `dyn Trait` type.
2766
+ #[ cfg_attr( kani, derive( kani:: Arbitrary ) ) ]
2766
2767
struct TestStruct {
2767
2768
value : i64 ,
2768
2769
}
@@ -2775,7 +2776,7 @@ mod verify {
2775
2776
/// - `$proof_name`: Specifies the name of the generated proof for contract.
2776
2777
macro_rules! gen_mut_byte_arith_harness_for_dyn {
2777
2778
( 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
2779
2780
// Workaround: Directly verifying the method `<*mut dyn TestTrait>::byte_offset`
2780
2781
// causes a compilation error. As a workaround, the proof is annotated with the
2781
2782
// underlying struct type instead.
@@ -2793,7 +2794,7 @@ mod verify {
2793
2794
}
2794
2795
} ;
2795
2796
( $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
2797
2798
// Workaround: Directly verifying the method `<*mut dyn TestTrait>::$fn_name`
2798
2799
// causes a compilation error. As a workaround, the proof is annotated with the
2799
2800
// underlying struct type instead.
@@ -3013,4 +3014,30 @@ mod verify {
3013
3014
generate_mut_byte_offset_from_slice_harness ! ( i64 , check_mut_byte_offset_from_i64_slice) ;
3014
3015
generate_mut_byte_offset_from_slice_harness ! ( i128 , check_mut_byte_offset_from_i128_slice) ;
3015
3016
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
+ }
3016
3043
}
0 commit comments