@@ -43,13 +43,11 @@ use crate::convert::TryInto as _;
4343use crate :: slice:: memchr;
4444use crate :: { cmp, fmt} ;
4545
46- #[ cfg( all( target_arch = "x86_64" , any( kani, target_feature = "sse2" ) ) ) ] // only called on x86
46+ #[ cfg( all( target_arch = "x86_64" , any( kani, target_feature = "sse2" ) ) ) ]
4747use safety:: { loop_invariant, requires} ;
4848
4949#[ cfg( kani) ]
5050use crate :: kani;
51- #[ cfg( kani) ]
52- use crate :: kani:: mem:: same_allocation;
5351
5452// Pattern
5553
@@ -1960,7 +1958,8 @@ unsafe fn small_slice_eq(x: &[u8], y: &[u8]) -> bool {
19601958 unsafe {
19611959 let ( mut px, mut py) = ( x. as_ptr ( ) , y. as_ptr ( ) ) ;
19621960 let ( pxend, pyend) = ( px. add ( x. len ( ) - 4 ) , py. add ( y. len ( ) - 4 ) ) ;
1963- #[ loop_invariant( same_allocation( x. as_ptr( ) , px) && same_allocation( y. as_ptr( ) , py)
1961+ #[ loop_invariant( crate :: ub_checks:: same_allocation( x. as_ptr( ) , px)
1962+ && crate :: ub_checks:: same_allocation( y. as_ptr( ) , py)
19641963 && px as isize >= x. as_ptr( ) as isize
19651964 && py as isize >= y. as_ptr( ) as isize
19661965 && px as isize - x. as_ptr( ) as isize == ( py as isize - y. as_ptr( ) as isize ) ) ]
@@ -2000,4 +1999,23 @@ pub mod verify {
20001999 small_slice_eq ( xs, ys) ;
20012000 }
20022001 }
2002+
2003+ #[ cfg( all( kani, target_arch = "x86_64" ) ) ] // only called on x86
2004+ #[ kani:: proof]
2005+ #[ kani:: unwind( 4 ) ]
2006+ pub fn check_small_slice_eq_empty ( ) {
2007+ let ptr_x = kani:: any_where :: < usize , _ > ( |val| * val != 0 ) as * const u8 ;
2008+ let ptr_y = kani:: any_where :: < usize , _ > ( |val| * val != 0 ) as * const u8 ;
2009+ kani:: assume ( ptr_x. is_aligned ( ) ) ;
2010+ kani:: assume ( ptr_y. is_aligned ( ) ) ;
2011+ unsafe {
2012+ assert_eq ! (
2013+ small_slice_eq(
2014+ crate :: slice:: from_raw_parts( ptr_x, 0 ) ,
2015+ crate :: slice:: from_raw_parts( ptr_y, 0 ) ,
2016+ ) ,
2017+ true
2018+ ) ;
2019+ }
2020+ }
20032021}
0 commit comments