diff options
| author | Ralf Jung <post@ralfj.de> | 2022-07-24 14:04:26 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-24 14:04:26 -0400 |
| commit | 890cd7a496b8002debead4b970bd2f24dcb9c014 (patch) | |
| tree | 1bc9dbdce55f7c08204622e3c6f9bb9ed167426a /compiler/rustc_middle | |
| parent | c32dcbba187d1ee0dbe92dc152cb9c2f3f42900c (diff) | |
| parent | 4e89a7c29325964182e0fb9f92539cf2d9f18e82 (diff) | |
| download | rust-890cd7a496b8002debead4b970bd2f24dcb9c014.tar.gz rust-890cd7a496b8002debead4b970bd2f24dcb9c014.zip | |
Rollup merge of #99644 - RalfJung:interpret-int-ptr-transmute, r=oli-obk
remove some provenance-related machine hooks that Miri no longer needs Then we can make `scalar_to_ptr` a method on `Scalar`. :) Fixes https://github.com/rust-lang/miri/issues/2188 r? `@oli-obk`
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/mir/interpret/value.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/value.rs b/compiler/rustc_middle/src/mir/interpret/value.rs index 17088cf13a5..834c114ee1c 100644 --- a/compiler/rustc_middle/src/mir/interpret/value.rs +++ b/compiler/rustc_middle/src/mir/interpret/value.rs @@ -331,6 +331,19 @@ impl<Prov> Scalar<Prov> { } impl<'tcx, Prov: Provenance> Scalar<Prov> { + pub fn to_pointer(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, Pointer<Option<Prov>>> { + match self + .to_bits_or_ptr_internal(cx.pointer_size()) + .map_err(|s| err_ub!(ScalarSizeMismatch(s)))? + { + Err(ptr) => Ok(ptr.into()), + Ok(bits) => { + let addr = u64::try_from(bits).unwrap(); + Ok(Pointer::from_addr(addr)) + } + } + } + /// Fundamental scalar-to-int (cast) operation. Many convenience wrappers exist below, that you /// likely want to use instead. /// @@ -547,6 +560,11 @@ impl<Prov> ScalarMaybeUninit<Prov> { impl<'tcx, Prov: Provenance> ScalarMaybeUninit<Prov> { #[inline(always)] + pub fn to_pointer(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, Pointer<Option<Prov>>> { + self.check_init()?.to_pointer(cx) + } + + #[inline(always)] pub fn to_bool(self) -> InterpResult<'tcx, bool> { self.check_init()?.to_bool() } |
