Skip to content

Commit 7565b5a

Browse files
committed
machine hooks for ptr (de)ref also need layout, and then they do not need the size
1 parent 0d596f2 commit 7565b5a

File tree

2 files changed

+19
-31
lines changed

2 files changed

+19
-31
lines changed

src/librustc_mir/interpret/machine.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use std::hash::Hash;
1717

1818
use rustc::hir::{self, def_id::DefId};
1919
use rustc::mir;
20-
use rustc::ty::{self, Ty, layout::{Size, TyLayout}, query::TyCtxtAt};
20+
use rustc::ty::{self, layout::{Size, TyLayout}, query::TyCtxtAt};
2121

2222
use super::{
2323
Allocation, AllocId, EvalResult, Scalar,
24-
EvalContext, PlaceTy, OpTy, Pointer, MemPlace, MemoryKind,
24+
EvalContext, PlaceTy, MPlaceTy, OpTy, Pointer, MemoryKind,
2525
};
2626

2727
/// Whether this kind of memory is allowed to leak
@@ -217,26 +217,22 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized {
217217
#[inline]
218218
fn tag_reference(
219219
_ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
220-
place: MemPlace<Self::PointerTag>,
221-
_ty: Ty<'tcx>,
222-
_size: Size,
220+
place: MPlaceTy<'tcx, Self::PointerTag>,
223221
_mutability: Option<hir::Mutability>,
224-
) -> EvalResult<'tcx, MemPlace<Self::PointerTag>> {
225-
Ok(place)
222+
) -> EvalResult<'tcx, Scalar<Self::PointerTag>> {
223+
Ok(place.ptr)
226224
}
227225

228226
/// Executed when evaluating the `*` operator: Following a reference.
229-
/// This has the change to adjust the tag. It should not change anything else!
227+
/// This has the chance to adjust the tag. It should not change anything else!
230228
/// `mutability` can be `None` in case a raw ptr is being dereferenced.
231229
#[inline]
232230
fn tag_dereference(
233231
_ecx: &EvalContext<'a, 'mir, 'tcx, Self>,
234-
place: MemPlace<Self::PointerTag>,
235-
_ty: Ty<'tcx>,
236-
_size: Size,
232+
place: MPlaceTy<'tcx, Self::PointerTag>,
237233
_mutability: Option<hir::Mutability>,
238-
) -> EvalResult<'tcx, MemPlace<Self::PointerTag>> {
239-
Ok(place)
234+
) -> EvalResult<'tcx, Scalar<Self::PointerTag>> {
235+
Ok(place.ptr)
240236
}
241237

242238
/// Execute a validation operation

src/librustc_mir/interpret/place.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -278,42 +278,34 @@ where
278278
let meta = val.to_meta()?;
279279
let ptr = val.to_scalar_ptr()?;
280280
let mplace = MemPlace { ptr, align, meta };
281+
let mut mplace = MPlaceTy { mplace, layout };
281282
// Pointer tag tracking might want to adjust the tag.
282-
let mplace = if M::ENABLE_PTR_TRACKING_HOOKS {
283-
let (size, _) = self.size_and_align_of(meta, layout)?
284-
// for extern types, just cover what we can
285-
.unwrap_or_else(|| layout.size_and_align());
283+
if M::ENABLE_PTR_TRACKING_HOOKS {
286284
let mutbl = match val.layout.ty.sty {
287285
// `builtin_deref` considers boxes immutable, that's useless for our purposes
288286
ty::Ref(_, _, mutbl) => Some(mutbl),
289287
ty::Adt(def, _) if def.is_box() => Some(hir::MutMutable),
290288
ty::RawPtr(_) => None,
291289
_ => bug!("Unexpected pointer type {}", val.layout.ty.sty),
292290
};
293-
M::tag_dereference(self, mplace, pointee_type, size, mutbl)?
294-
} else {
295-
mplace
296-
};
297-
Ok(MPlaceTy { mplace, layout })
291+
mplace.mplace.ptr = M::tag_dereference(self, mplace, mutbl)?;
292+
}
293+
// Done
294+
Ok(mplace)
298295
}
299296

300297
/// Turn a mplace into a (thin or fat) pointer, as a reference, pointing to the same space.
301298
/// This is the inverse of `ref_to_mplace`.
302299
/// `mutbl` indicates whether we are create a shared or mutable ref, or a raw pointer (`None`).
303300
pub fn create_ref(
304301
&mut self,
305-
place: MPlaceTy<'tcx, M::PointerTag>,
302+
mut place: MPlaceTy<'tcx, M::PointerTag>,
306303
mutbl: Option<hir::Mutability>,
307304
) -> EvalResult<'tcx, Immediate<M::PointerTag>> {
308305
// Pointer tag tracking might want to adjust the tag
309-
let place = if M::ENABLE_PTR_TRACKING_HOOKS {
310-
let (size, _) = self.size_and_align_of_mplace(place)?
311-
// for extern types, just cover what we can
312-
.unwrap_or_else(|| place.layout.size_and_align());
313-
M::tag_reference(self, *place, place.layout.ty, size, mutbl)?
314-
} else {
315-
*place
316-
};
306+
if M::ENABLE_PTR_TRACKING_HOOKS {
307+
place.mplace.ptr = M::tag_reference(self, place, mutbl)?
308+
}
317309
Ok(match place.meta {
318310
None => Immediate::Scalar(place.ptr.into()),
319311
Some(meta) => Immediate::ScalarPair(place.ptr.into(), meta.into()),

0 commit comments

Comments
 (0)