@@ -590,11 +590,14 @@ pub const fn null_mut<T: ?Sized + Thin>() -> *mut T {
590590#[ unstable( feature = "strict_provenance" , issue = "95228" ) ]
591591pub const fn without_provenance < T > ( addr : usize ) -> * const T {
592592 // FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
593- // We use transmute rather than a cast so tools like Miri can tell that this
594- // is *not* the same as from_exposed_addr.
595- // SAFETY: every valid integer is also a valid pointer (as long as you don't dereference that
596- // pointer).
597- unsafe { mem:: transmute ( addr) }
593+ // FIXME(maybe): simply transmute the address once codegen lowers that correctly.
594+ // We offset the null pointer instead of using a cast so that this lowers to
595+ // getelementptr instead of inttoptr.
596+ // We use transmute instead of casting so that in miri the pointer truly
597+ // has no provenance.
598+ // SAFETY: on all current platforms, usize and pointers have the same layout,
599+ // and the validity invariant of pointers is the same as that of integers
600+ unsafe { mem:: transmute :: < _ , * const T > ( 0usize ) . wrapping_byte_add ( addr) }
598601}
599602
600603/// Creates a new pointer that is dangling, but well-aligned.
@@ -632,11 +635,14 @@ pub const fn dangling<T>() -> *const T {
632635#[ unstable( feature = "strict_provenance" , issue = "95228" ) ]
633636pub const fn without_provenance_mut < T > ( addr : usize ) -> * mut T {
634637 // FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
635- // We use transmute rather than a cast so tools like Miri can tell that this
636- // is *not* the same as from_exposed_addr.
637- // SAFETY: every valid integer is also a valid pointer (as long as you don't dereference that
638- // pointer).
639- unsafe { mem:: transmute ( addr) }
638+ // FIXME(maybe): simply transmute the address once codegen lowers that correctly.
639+ // We offset the null pointer instead of using a cast so that this lowers to
640+ // getelementptr instead of inttoptr.
641+ // We use transmute instead of casting so that in miri the pointer truly
642+ // has no provenance.
643+ // SAFETY: on all current platforms, usize and pointers have the same layout,
644+ // and the validity invariant of pointers is the same as that of integers
645+ unsafe { mem:: transmute :: < _ , * mut T > ( 0usize ) . wrapping_byte_add ( addr) }
640646}
641647
642648/// Creates a new pointer that is dangling, but well-aligned.
0 commit comments