diff --git a/crossbeam-epoch/src/atomic.rs b/crossbeam-epoch/src/atomic.rs index b31926dc1..e20a6587b 100644 --- a/crossbeam-epoch/src/atomic.rs +++ b/crossbeam-epoch/src/atomic.rs @@ -63,26 +63,26 @@ fn ensure_aligned(raw: *mut ()) { /// `tag` is truncated to fit into the unused bits of the pointer to `T`. #[inline] fn compose_tag(ptr: *mut (), tag: usize) -> *mut () { - int_to_ptr_with_provenance( - (ptr as usize & !low_bits::()) | (tag & low_bits::()), - ptr, - ) + map_addr(ptr, |a| (a & !low_bits::()) | (tag & low_bits::())) } /// Decomposes a tagged pointer `data` into the pointer and the tag. #[inline] fn decompose_tag(ptr: *mut ()) -> (*mut (), usize) { ( - int_to_ptr_with_provenance(ptr as usize & !low_bits::(), ptr), + map_addr(ptr, |a| a & !low_bits::()), ptr as usize & low_bits::(), ) } -// HACK: https://github.com/rust-lang/miri/issues/1866#issuecomment-985802751 +// FIXME: This is exactly , +// which we cannot use yet due to the MSRV. #[inline] -fn int_to_ptr_with_provenance(addr: usize, prov: *mut T) -> *mut T { - let ptr = prov.cast::(); - ptr.wrapping_add(addr.wrapping_sub(ptr as usize)).cast() +fn map_addr(ptr: *mut T, f: impl FnOnce(usize) -> usize) -> *mut T { + let new_addr = f(ptr as usize); + ptr.cast::() + .wrapping_add(new_addr.wrapping_sub(ptr as usize)) + .cast::() } /// Types that are pointed to by a single word. @@ -640,9 +640,7 @@ impl Atomic { let fetch_order = strongest_failure_ordering(order); Shared::from_ptr( self.data - .fetch_update(order, fetch_order, |x| { - Some(int_to_ptr_with_provenance(x as usize & val, x)) - }) + .fetch_update(order, fetch_order, |x| Some(map_addr(x, |a| a & val))) .unwrap(), ) } @@ -687,9 +685,7 @@ impl Atomic { let fetch_order = strongest_failure_ordering(order); Shared::from_ptr( self.data - .fetch_update(order, fetch_order, |x| { - Some(int_to_ptr_with_provenance(x as usize | val, x)) - }) + .fetch_update(order, fetch_order, |x| Some(map_addr(x, |a| a | val))) .unwrap(), ) } @@ -734,9 +730,7 @@ impl Atomic { let fetch_order = strongest_failure_ordering(order); Shared::from_ptr( self.data - .fetch_update(order, fetch_order, |x| { - Some(int_to_ptr_with_provenance(x as usize ^ val, x)) - }) + .fetch_update(order, fetch_order, |x| Some(map_addr(x, |a| a ^ val))) .unwrap(), ) }