From 005df5fe03ba2f9cdb7ed58d7cfb2c194184cc28 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 28 Nov 2018 09:22:02 +0100 Subject: [PATCH] provide a way to replace the tag in a Scalar/MemPlace --- src/librustc/mir/interpret/value.rs | 8 ++++++++ src/librustc_mir/interpret/place.rs | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 4bcba9d54674..500bd47dfbe7 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -138,6 +138,14 @@ impl<'tcx, Tag> Scalar { } } + #[inline] + pub fn with_tag(self, new_tag: Tag) -> Self { + match self { + Scalar::Ptr(ptr) => Scalar::Ptr(Pointer { tag: new_tag, ..ptr }), + Scalar::Bits { bits, size } => Scalar::Bits { bits, size }, + } + } + #[inline] pub fn ptr_null(cx: &impl HasDataLayout) -> Self { Scalar::Bits { diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 1b47530eaec6..164a9680c797 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -115,6 +115,16 @@ impl MemPlace { } } + #[inline] + pub fn with_tag(self, new_tag: Tag) -> Self + { + MemPlace { + ptr: self.ptr.with_tag(new_tag), + align: self.align, + meta: self.meta, + } + } + #[inline(always)] pub fn from_scalar_ptr(ptr: Scalar, align: Align) -> Self { MemPlace { @@ -187,6 +197,16 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> { } } + #[inline] + pub fn with_tag(self, new_tag: Tag) -> Self + { + MPlaceTy { + mplace: self.mplace.with_tag(new_tag), + layout: self.layout, + } + } + + #[inline] pub fn offset( self, offset: Size,