Closed
Description
Since right now miri's pointer comparison bails out on &x as *const T < &y as *const T
but allows &x as *const T == &y as *const T
, I suggest to also allow <
. This will not impact ctfe-mode, since ctfe mode disallows any binary ops on pointers into different allocs, even ==
.
It's deterministic between multiple miri runs, doesn't leak HashMap
ordering and only depends on optimizations and codegen from rustc (but that's already true for ==
).
Steps to do:
- Implement force_bits, force_int and basic address assignment.
- force_bits when doing primitive operations.
- force_bits when doing casts.
- force_ptr when creating a non-ZST reference. (Ideally through
check_ptr_access
? Redundant with validity checks but whatever.) We may need aforce_ptr_place
method or so; the freeze-sensitive visitor also needs that. - Make force_bits infallible (in Miri, not CTFE) -- see Make force_ptr a total operation, and ptr-to-int-casts not require extra machine state #841.
-
force_bits when doing partial loads of a pointer -- and really everywhere we need a ptr, once it is total. (For now let's not do this, also see const-eval: load of partially initialized scalar produces entirely uninitialized result rust#69488 for a similar problem around partially initialized data.) - Exploit "real" pointer alignment for alignment checks, but warn when we do. (But also see align_offset guarantees rust#62420.)
- Ptr-to-int of a dangling pointer (possible in safe code).
- Fix the FIXMEs added in Add tests for Intptrcast when doing explicit casts #803.
- Audit all remaining uses of to_bits (this includes the
to_<int type>
methods...), to_ptr and to_bits_or_ptr, all uses of is_ptr and is_bits, and also all uses offorce_ptr
andforce_mplace_ptr
(alsomplace_access_checked
,check_mplace_access
) outside ofcheck_ptr_access
. Maybe replace to_{bits,ptr} by assert_{bits,ptr}?