@@ -36,7 +36,7 @@ const fn memchr_naive(x: u8, text: &[u8]) -> Option<usize> {
36
36
let mut i = 0 ;
37
37
38
38
// FIXME(const-hack): Replace with `text.iter().pos(|c| *c == x)`.
39
- #[ safety:: loop_invariant( true ) ]
39
+ #[ safety:: loop_invariant( i <= text . len ( ) && kani :: forall! ( |j in ( 0 , i ) | unsafe { * text . as_ptr ( ) . wrapping_add ( j ) } != x ) ) ]
40
40
while i < text. len ( ) {
41
41
if text[ i] == x {
42
42
return Some ( i) ;
@@ -79,7 +79,8 @@ const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
79
79
80
80
// search the body of the text
81
81
let repeated_x = usize :: repeat_u8( x) ;
82
- #[ safety:: loop_invariant( len >= 2 * USIZE_BYTES && offset <= len) ]
82
+ #[ safety:: loop_invariant( len >= 2 * USIZE_BYTES && offset <= len &&
83
+ kani:: forall!( |j in ( 0 , offset) | unsafe { * text. as_ptr( ) . wrapping_add( j) } != x) ) ]
83
84
while offset <= len - 2 * USIZE_BYTES {
84
85
// SAFETY: the while's predicate guarantees a distance of at least 2 * usize_bytes
85
86
// between the offset and the end of the slice.
@@ -170,22 +171,21 @@ pub mod verify {
170
171
use crate :: kani;
171
172
172
173
#[ kani:: proof]
174
+ #[ kani:: solver( cvc5) ]
173
175
#[ cfg( not( all( target_arch = "x86_64" , target_feature = "sse2" ) ) ) ]
174
176
pub fn check_memchr_naive ( ) {
175
- const ARR_SIZE : usize = 1000 ;
177
+ const ARR_SIZE : usize = 64 ;
176
178
let x: u8 = kani:: any ( ) ;
177
- let a: [ u8 ; ARR_SIZE ] = kani:: any ( ) ;
178
- let text = kani:: slice:: any_slice_of_array ( & a) ;
179
- let _result = memchr_naive ( x, text) ;
179
+ let text: [ u8 ; ARR_SIZE ] = kani:: any ( ) ;
180
+ let _result = memchr_naive ( x, & text) ;
180
181
}
181
182
182
183
#[ kani:: proof]
183
184
#[ cfg( not( all( target_arch = "x86_64" , target_feature = "sse2" ) ) ) ]
184
185
pub fn check_memchr ( ) {
185
- const ARR_SIZE : usize = 1000 ;
186
+ const ARR_SIZE : usize = 64 ;
186
187
let x: u8 = kani:: any ( ) ;
187
- let a: [ u8 ; ARR_SIZE ] = kani:: any ( ) ;
188
- let text = kani:: slice:: any_slice_of_array ( & a) ;
189
- let _result = memrchr ( x, text) ;
188
+ let text: [ u8 ; ARR_SIZE ] = kani:: any ( ) ;
189
+ let _result = memrchr ( x, & text) ;
190
190
}
191
191
}
0 commit comments