use rustc::hir::{self, def_id::DefId};
use rustc::mir;
-use rustc::ty::{self, Ty, layout::{Size, TyLayout}, query::TyCtxtAt};
+use rustc::ty::{self, layout::{Size, TyLayout}, query::TyCtxtAt};
use super::{
Allocation, AllocId, EvalResult, Scalar,
- EvalContext, PlaceTy, OpTy, Pointer, MemPlace, MemoryKind,
+ EvalContext, PlaceTy, MPlaceTy, OpTy, Pointer, MemoryKind,
};
/// Whether this kind of memory is allowed to leak
#[inline]
fn tag_reference(
_ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
- place: MemPlace<Self::PointerTag>,
- _ty: Ty<'tcx>,
- _size: Size,
+ place: MPlaceTy<'tcx, Self::PointerTag>,
_mutability: Option<hir::Mutability>,
- ) -> EvalResult<'tcx, MemPlace<Self::PointerTag>> {
- Ok(place)
+ ) -> EvalResult<'tcx, Scalar<Self::PointerTag>> {
+ Ok(place.ptr)
}
/// Executed when evaluating the `*` operator: Following a reference.
- /// This has the change to adjust the tag. It should not change anything else!
+ /// This has the chance to adjust the tag. It should not change anything else!
/// `mutability` can be `None` in case a raw ptr is being dereferenced.
#[inline]
fn tag_dereference(
_ecx: &EvalContext<'a, 'mir, 'tcx, Self>,
- place: MemPlace<Self::PointerTag>,
- _ty: Ty<'tcx>,
- _size: Size,
+ place: MPlaceTy<'tcx, Self::PointerTag>,
_mutability: Option<hir::Mutability>,
- ) -> EvalResult<'tcx, MemPlace<Self::PointerTag>> {
- Ok(place)
+ ) -> EvalResult<'tcx, Scalar<Self::PointerTag>> {
+ Ok(place.ptr)
}
/// Execute a validation operation
let meta = val.to_meta()?;
let ptr = val.to_scalar_ptr()?;
let mplace = MemPlace { ptr, align, meta };
+ let mut mplace = MPlaceTy { mplace, layout };
// Pointer tag tracking might want to adjust the tag.
- let mplace = if M::ENABLE_PTR_TRACKING_HOOKS {
- let (size, _) = self.size_and_align_of(meta, layout)?
- // for extern types, just cover what we can
- .unwrap_or_else(|| layout.size_and_align());
+ if M::ENABLE_PTR_TRACKING_HOOKS {
let mutbl = match val.layout.ty.sty {
// `builtin_deref` considers boxes immutable, that's useless for our purposes
ty::Ref(_, _, mutbl) => Some(mutbl),
ty::RawPtr(_) => None,
_ => bug!("Unexpected pointer type {}", val.layout.ty.sty),
};
- M::tag_dereference(self, mplace, pointee_type, size, mutbl)?
- } else {
- mplace
- };
- Ok(MPlaceTy { mplace, layout })
+ mplace.mplace.ptr = M::tag_dereference(self, mplace, mutbl)?;
+ }
+ // Done
+ Ok(mplace)
}
/// Turn a mplace into a (thin or fat) pointer, as a reference, pointing to the same space.
/// `mutbl` indicates whether we are create a shared or mutable ref, or a raw pointer (`None`).
pub fn create_ref(
&mut self,
- place: MPlaceTy<'tcx, M::PointerTag>,
+ mut place: MPlaceTy<'tcx, M::PointerTag>,
mutbl: Option<hir::Mutability>,
) -> EvalResult<'tcx, Immediate<M::PointerTag>> {
// Pointer tag tracking might want to adjust the tag
- let place = if M::ENABLE_PTR_TRACKING_HOOKS {
- let (size, _) = self.size_and_align_of_mplace(place)?
- // for extern types, just cover what we can
- .unwrap_or_else(|| place.layout.size_and_align());
- M::tag_reference(self, *place, place.layout.ty, size, mutbl)?
- } else {
- *place
- };
+ if M::ENABLE_PTR_TRACKING_HOOKS {
+ place.mplace.ptr = M::tag_reference(self, place, mutbl)?
+ }
Ok(match place.meta {
None => Immediate::Scalar(place.ptr.into()),
Some(meta) => Immediate::ScalarPair(place.ptr.into(), meta.into()),