1//! Computations on places -- field projections, going from mir::Place, and writing
2//! into a place.
3//! All high-level functions to write to memory work on places as destinations.
45use std::assert_matches;
67use either::{Either, Left, Right};
8use rustc_abi::{BackendRepr, HasDataLayout, Size};
9use rustc_middle::mir;
10use rustc_middle::ty::layout::TyAndLayout;
11use rustc_middle::ty::{self, Ty};
12use rustc_span::{bug, span_bug};
13use tracing::field::Empty;
14use tracing::{instrument, trace};
1516use super::{
17AllocInit, AllocRef, AllocRefMut, CheckAlignMsg, CheckInAllocMsg, CtfeProvenance, ImmTy,
18Immediate, InterpCx, InterpResult, Machine, MemoryKind, Misalignment, OffsetMode, OpTy,
19Operand, Pointer, Projectable, Provenance, Scalar, alloc_range, err_ub, err_ub_format,
20interp_ok, mir_assign_valid_types, throw_ub_format,
21};
22use crate::enter_trace_span;
2324#[derive(#[automatically_derived]
impl<Prov: ::core::marker::Copy + Provenance> ::core::marker::Copy for
MemPlaceMeta<Prov> {
}Copy, #[automatically_derived]
impl<Prov: ::core::clone::Clone + Provenance> ::core::clone::Clone for
MemPlaceMeta<Prov> {
#[inline]
fn clone(&self) -> MemPlaceMeta<Prov> {
match self {
MemPlaceMeta::Meta(__self_0) =>
MemPlaceMeta::Meta(::core::clone::Clone::clone(__self_0)),
MemPlaceMeta::None => MemPlaceMeta::None,
}
}
}Clone, #[automatically_derived]
impl<Prov: ::core::hash::Hash + Provenance> ::core::hash::Hash for
MemPlaceMeta<Prov> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
MemPlaceMeta::Meta(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash, #[automatically_derived]
impl<Prov: ::core::cmp::PartialEq + Provenance>
::core::marker::StructuralPartialEq for MemPlaceMeta<Prov> {
}
#[automatically_derived]
impl<Prov: ::core::cmp::PartialEq + Provenance> ::core::cmp::PartialEq for
MemPlaceMeta<Prov> {
#[inline]
fn eq(&self, other: &MemPlaceMeta<Prov>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(MemPlaceMeta::Meta(__self_0), MemPlaceMeta::Meta(__arg1_0))
=> __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl<Prov: ::core::cmp::Eq + Provenance> ::core::cmp::Eq for
MemPlaceMeta<Prov> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Scalar<Prov>>;
}
}Eq, #[automatically_derived]
impl<Prov: ::core::fmt::Debug + Provenance> ::core::fmt::Debug for
MemPlaceMeta<Prov> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
MemPlaceMeta::Meta(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Meta",
&__self_0),
MemPlaceMeta::None =>
::core::fmt::Formatter::write_str(f, "None"),
}
}
}Debug)]
25/// Information required for the sound usage of a `MemPlace`.
26pub enum MemPlaceMeta<Prov: Provenance = CtfeProvenance> {
27/// The unsized payload (e.g. length for slices or vtable pointer for trait objects).
28Meta(Scalar<Prov>),
29/// `Sized` types or unsized `extern type`
30None,
31}
3233impl<Prov: Provenance> MemPlaceMeta<Prov> {
34#[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
35pub fn unwrap_meta(self) -> Scalar<Prov> {
36match self {
37Self::Meta(s) => s,
38Self::None => {
39bug_impl(None,
format_args!("expected wide pointer extra data (e.g. slice length or trait object vtable)"),
Location::caller())bug!("expected wide pointer extra data (e.g. slice length or trait object vtable)")40 }
41 }
42 }
4344#[inline(always)]
45pub fn has_meta(self) -> bool {
46match self {
47Self::Meta(_) => true,
48Self::None => false,
49 }
50 }
51}
5253#[derive(#[automatically_derived]
impl<Prov: ::core::marker::Copy + Provenance> ::core::marker::Copy for
MemPlace<Prov> {
}Copy, #[automatically_derived]
impl<Prov: ::core::clone::Clone + Provenance> ::core::clone::Clone for
MemPlace<Prov> {
#[inline]
fn clone(&self) -> MemPlace<Prov> {
MemPlace {
ptr: ::core::clone::Clone::clone(&self.ptr),
meta: ::core::clone::Clone::clone(&self.meta),
misaligned: ::core::clone::Clone::clone(&self.misaligned),
}
}
}Clone, #[automatically_derived]
impl<Prov: ::core::hash::Hash + Provenance> ::core::hash::Hash for
MemPlace<Prov> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.ptr, state);
::core::hash::Hash::hash(&self.meta, state);
::core::hash::Hash::hash(&self.misaligned, state)
}
}Hash, #[automatically_derived]
impl<Prov: ::core::cmp::PartialEq + Provenance>
::core::marker::StructuralPartialEq for MemPlace<Prov> {
}
#[automatically_derived]
impl<Prov: ::core::cmp::PartialEq + Provenance> ::core::cmp::PartialEq for
MemPlace<Prov> {
#[inline]
fn eq(&self, other: &MemPlace<Prov>) -> bool {
self.ptr == other.ptr && self.meta == other.meta &&
self.misaligned == other.misaligned
}
}PartialEq, #[automatically_derived]
impl<Prov: ::core::cmp::Eq + Provenance> ::core::cmp::Eq for MemPlace<Prov> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Pointer<Option<Prov>>>;
let _: ::core::cmp::AssertParamIsEq<MemPlaceMeta<Prov>>;
let _: ::core::cmp::AssertParamIsEq<Option<Misalignment>>;
}
}Eq, #[automatically_derived]
impl<Prov: ::core::fmt::Debug + Provenance> ::core::fmt::Debug for
MemPlace<Prov> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "MemPlace",
"ptr", &self.ptr, "meta", &self.meta, "misaligned",
&&self.misaligned)
}
}Debug)]
54pub(super) struct MemPlace<Prov: Provenance = CtfeProvenance> {
55/// The pointer can be a pure integer, with the `None` provenance.
56pub ptr: Pointer<Option<Prov>>,
57/// Metadata for unsized places. Interpretation is up to the type.
58 /// Must not be present for sized types, but can be missing for unsized types
59 /// (e.g., `extern type`).
60pub meta: MemPlaceMeta<Prov>,
61/// Stores whether this place was created based on a sufficiently aligned pointer.
62misaligned: Option<Misalignment>,
63}
6465impl<Prov: Provenance> MemPlace<Prov> {
66/// Adjust the provenance of the main pointer (metadata is unaffected).
67fn map_provenance(self, f: impl FnOnce(Prov) -> Prov) -> Self {
68MemPlace { ptr: self.ptr.map_provenance(|p| p.map(f)), ..self }
69 }
7071/// Turn a mplace into a (thin or wide) pointer, as a reference, pointing to the same space.
72#[inline]
73fn to_ref(self, cx: &impl HasDataLayout) -> Immediate<Prov> {
74Immediate::new_pointer_with_meta(self.ptr, self.meta, cx)
75 }
7677#[inline]
78// Not called `offset_with_meta` to avoid confusion with the trait method.
79fn offset_with_meta_<'tcx, M: Machine<'tcx, Provenance = Prov>>(
80self,
81 offset: Size,
82 mode: OffsetMode,
83 meta: MemPlaceMeta<Prov>,
84 ecx: &InterpCx<'tcx, M>,
85 ) -> InterpResult<'tcx, Self> {
86if true {
if !(!meta.has_meta() || self.meta.has_meta()) {
{
::core::panicking::panic_fmt(format_args!("cannot use `offset_with_meta` to add metadata to a place"));
}
};
};debug_assert!(
87 !meta.has_meta() || self.meta.has_meta(),
88"cannot use `offset_with_meta` to add metadata to a place"
89);
90let ptr = match mode {
91 OffsetMode::Inbounds => {
92 ecx.ptr_offset_inbounds(self.ptr, offset.bytes().try_into().unwrap())?
93}
94 OffsetMode::Wrapping => self.ptr.wrapping_offset(offset, ecx),
95 };
96interp_ok(MemPlace { ptr, meta, misaligned: self.misaligned })
97 }
98}
99100/// A MemPlace with its layout. Constructing it is only possible in this module.
101#[derive(#[automatically_derived]
impl<'tcx, Prov: ::core::clone::Clone + Provenance> ::core::clone::Clone for
MPlaceTy<'tcx, Prov> {
#[inline]
fn clone(&self) -> MPlaceTy<'tcx, Prov> {
MPlaceTy {
mplace: ::core::clone::Clone::clone(&self.mplace),
layout: ::core::clone::Clone::clone(&self.layout),
}
}
}Clone, #[automatically_derived]
impl<'tcx, Prov: ::core::hash::Hash + Provenance> ::core::hash::Hash for
MPlaceTy<'tcx, Prov> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.mplace, state);
::core::hash::Hash::hash(&self.layout, state)
}
}Hash, #[automatically_derived]
impl<'tcx, Prov: ::core::cmp::Eq + Provenance> ::core::cmp::Eq for
MPlaceTy<'tcx, Prov> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<MemPlace<Prov>>;
let _: ::core::cmp::AssertParamIsEq<TyAndLayout<'tcx>>;
}
}Eq, #[automatically_derived]
impl<'tcx, Prov: ::core::cmp::PartialEq + Provenance>
::core::marker::StructuralPartialEq for MPlaceTy<'tcx, Prov> {
}
#[automatically_derived]
impl<'tcx, Prov: ::core::cmp::PartialEq + Provenance> ::core::cmp::PartialEq
for MPlaceTy<'tcx, Prov> {
#[inline]
fn eq(&self, other: &MPlaceTy<'tcx, Prov>) -> bool {
self.mplace == other.mplace && self.layout == other.layout
}
}PartialEq)]
102pub struct MPlaceTy<'tcx, Prov: Provenance = CtfeProvenance> {
103 mplace: MemPlace<Prov>,
104pub layout: TyAndLayout<'tcx>,
105}
106107impl<Prov: Provenance> std::fmt::Debugfor MPlaceTy<'_, Prov> {
108fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
109// Printing `layout` results in too much noise; just print a nice version of the type.
110f.debug_struct("MPlaceTy")
111 .field("mplace", &self.mplace)
112 .field("ty", &format_args!("{0}", self.layout.ty)format_args!("{}", self.layout.ty))
113 .finish()
114 }
115}
116117impl<'tcx, Prov: Provenance> MPlaceTy<'tcx, Prov> {
118/// Produces a MemPlace that works for ZST but nothing else.
119 /// Conceptually this is a new allocation, but it doesn't actually create an allocation so you
120 /// don't need to worry about memory leaks.
121#[inline]
122pub fn fake_alloc_zst(layout: TyAndLayout<'tcx>) -> Self {
123if !layout.is_zst() {
::core::panicking::panic("assertion failed: layout.is_zst()")
};assert!(layout.is_zst());
124let align = layout.align.abi;
125let ptr = Pointer::without_provenance(align.bytes()); // no provenance, absolute address
126MPlaceTy { mplace: MemPlace { ptr, meta: MemPlaceMeta::None, misaligned: None }, layout }
127 }
128129/// Adjust the provenance of the main pointer (metadata is unaffected).
130pub fn map_provenance(self, f: impl FnOnce(Prov) -> Prov) -> Self {
131MPlaceTy { mplace: self.mplace.map_provenance(f), ..self }
132 }
133134#[inline(always)]
135pub(super) fn mplace(&self) -> &MemPlace<Prov> {
136&self.mplace
137 }
138139#[inline(always)]
140pub fn ptr(&self) -> Pointer<Option<Prov>> {
141self.mplace.ptr
142 }
143144#[inline(always)]
145pub fn to_ref(&self, cx: &impl HasDataLayout) -> Immediate<Prov> {
146self.mplace.to_ref(cx)
147 }
148}
149150impl<'tcx, Prov: Provenance> Projectable<'tcx, Prov> for MPlaceTy<'tcx, Prov> {
151#[inline(always)]
152fn layout(&self) -> TyAndLayout<'tcx> {
153self.layout
154 }
155156#[inline(always)]
157fn meta(&self) -> MemPlaceMeta<Prov> {
158self.mplace.meta
159 }
160161fn offset_with_meta<M: Machine<'tcx, Provenance = Prov>>(
162&self,
163 offset: Size,
164 mode: OffsetMode,
165 meta: MemPlaceMeta<Prov>,
166 layout: TyAndLayout<'tcx>,
167 ecx: &InterpCx<'tcx, M>,
168 ) -> InterpResult<'tcx, Self> {
169interp_ok(MPlaceTy {
170 mplace: self.mplace.offset_with_meta_(offset, mode, meta, ecx)?,
171layout,
172 })
173 }
174175#[inline(always)]
176fn to_op<M: Machine<'tcx, Provenance = Prov>>(
177&self,
178 _ecx: &InterpCx<'tcx, M>,
179 ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
180interp_ok(self.clone().into())
181 }
182}
183184#[derive(#[automatically_derived]
impl<Prov: ::core::marker::Copy + Provenance> ::core::marker::Copy for
Place<Prov> {
}Copy, #[automatically_derived]
impl<Prov: ::core::clone::Clone + Provenance> ::core::clone::Clone for
Place<Prov> {
#[inline]
fn clone(&self) -> Place<Prov> {
match self {
Place::Ptr(__self_0) =>
Place::Ptr(::core::clone::Clone::clone(__self_0)),
Place::Local {
local: __self_0, offset: __self_1, locals_addr: __self_2 } =>
Place::Local {
local: ::core::clone::Clone::clone(__self_0),
offset: ::core::clone::Clone::clone(__self_1),
locals_addr: ::core::clone::Clone::clone(__self_2),
},
}
}
}Clone, #[automatically_derived]
impl<Prov: ::core::fmt::Debug + Provenance> ::core::fmt::Debug for Place<Prov>
{
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Place::Ptr(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Ptr",
&__self_0),
Place::Local {
local: __self_0, offset: __self_1, locals_addr: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f, "Local",
"local", __self_0, "offset", __self_1, "locals_addr",
&__self_2),
}
}
}Debug)]
185pub(super) enum Place<Prov: Provenance = CtfeProvenance> {
186/// A place referring to a value allocated in the `Memory` system.
187Ptr(MemPlace<Prov>),
188189/// To support alloc-free locals, we are able to write directly to a local. The offset indicates
190 /// where in the local this place is located; if it is `None`, no projection has been applied
191 /// and the type of the place is exactly the type of the local.
192 /// Such projections are meaningful even if the offset is 0, since they can change layouts.
193 /// (Without that optimization, we'd just always be a `MemPlace`.)
194 /// `Local` places always refer to the current stack frame, so they are unstable under
195 /// function calls/returns and switching betweens stacks of different threads!
196 /// We carry around the address of the `locals` buffer of the correct stack frame as a sanity
197 /// check to be able to catch some cases of using a dangling `Place`.
198 ///
199 /// This variant shall not be used for unsized types -- those must always live in memory.
200Local { local: mir::Local, offset: Option<Size>, locals_addr: usize },
201}
202203/// An evaluated place, together with its type.
204///
205/// This may reference a stack frame by its index, so `PlaceTy` should generally not be kept around
206/// for longer than a single operation. Popping and then pushing a stack frame can make `PlaceTy`
207/// point to the wrong destination. If the interpreter has multiple stacks, stack switching will
208/// also invalidate a `PlaceTy`.
209#[derive(#[automatically_derived]
impl<'tcx, Prov: ::core::clone::Clone + Provenance> ::core::clone::Clone for
PlaceTy<'tcx, Prov> {
#[inline]
fn clone(&self) -> PlaceTy<'tcx, Prov> {
PlaceTy {
place: ::core::clone::Clone::clone(&self.place),
layout: ::core::clone::Clone::clone(&self.layout),
}
}
}Clone)]
210pub struct PlaceTy<'tcx, Prov: Provenance = CtfeProvenance> {
211 place: Place<Prov>, // Keep this private; it helps enforce invariants.
212pub layout: TyAndLayout<'tcx>,
213}
214215impl<Prov: Provenance> std::fmt::Debugfor PlaceTy<'_, Prov> {
216fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
217// Printing `layout` results in too much noise; just print a nice version of the type.
218f.debug_struct("PlaceTy")
219 .field("place", &self.place)
220 .field("ty", &format_args!("{0}", self.layout.ty)format_args!("{}", self.layout.ty))
221 .finish()
222 }
223}
224225impl<'tcx, Prov: Provenance> From<MPlaceTy<'tcx, Prov>> for PlaceTy<'tcx, Prov> {
226#[inline(always)]
227fn from(mplace: MPlaceTy<'tcx, Prov>) -> Self {
228PlaceTy { place: Place::Ptr(mplace.mplace), layout: mplace.layout }
229 }
230}
231232impl<'tcx, Prov: Provenance> PlaceTy<'tcx, Prov> {
233#[inline(always)]
234pub(super) fn place(&self) -> &Place<Prov> {
235&self.place
236 }
237238/// A place is either an mplace or some local.
239 ///
240 /// Note that the return value can be different even for logically identical places!
241 /// Specifically, if a local is stored in-memory, this may return `Local` or `MPlaceTy`
242 /// depending on how the place was constructed. In other words, seeing `Local` here does *not*
243 /// imply that this place does not point to memory. Every caller must therefore always handle
244 /// both cases.
245#[inline(always)]
246pub fn as_mplace_or_local(
247&self,
248 ) -> Either<MPlaceTy<'tcx, Prov>, (mir::Local, Option<Size>, usize, TyAndLayout<'tcx>)> {
249match self.place {
250 Place::Ptr(mplace) => Left(MPlaceTy { mplace, layout: self.layout }),
251 Place::Local { local, offset, locals_addr } => {
252Right((local, offset, locals_addr, self.layout))
253 }
254 }
255 }
256257#[inline(always)]
258 #[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
259pub fn assert_mem_place(&self) -> MPlaceTy<'tcx, Prov> {
260self.as_mplace_or_local().left().unwrap_or_else(|| {
261bug_impl(None,
format_args!("PlaceTy of type {0} was a local when it was expected to be an MPlace",
self.layout.ty), Location::caller())bug!(
262"PlaceTy of type {} was a local when it was expected to be an MPlace",
263self.layout.ty
264 )265 })
266 }
267}
268269impl<'tcx, Prov: Provenance> Projectable<'tcx, Prov> for PlaceTy<'tcx, Prov> {
270#[inline(always)]
271fn layout(&self) -> TyAndLayout<'tcx> {
272self.layout
273 }
274275#[inline]
276fn meta(&self) -> MemPlaceMeta<Prov> {
277match self.as_mplace_or_local() {
278Left(mplace) => mplace.meta(),
279Right(_) => {
280if true {
if !self.layout.is_sized() {
{
::core::panicking::panic_fmt(format_args!("unsized locals should live in memory"));
}
};
};debug_assert!(self.layout.is_sized(), "unsized locals should live in memory");
281 MemPlaceMeta::None282 }
283 }
284 }
285286fn offset_with_meta<M: Machine<'tcx, Provenance = Prov>>(
287&self,
288 offset: Size,
289 mode: OffsetMode,
290 meta: MemPlaceMeta<Prov>,
291 layout: TyAndLayout<'tcx>,
292 ecx: &InterpCx<'tcx, M>,
293 ) -> InterpResult<'tcx, Self> {
294interp_ok(match self.as_mplace_or_local() {
295Left(mplace) => mplace.offset_with_meta(offset, mode, meta, layout, ecx)?.into(),
296Right((local, old_offset, locals_addr, _)) => {
297if true {
if !layout.is_sized() {
{
::core::panicking::panic_fmt(format_args!("unsized locals should live in memory"));
}
};
};debug_assert!(layout.is_sized(), "unsized locals should live in memory");
298{
match meta {
MemPlaceMeta::None => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"MemPlaceMeta::None", ::core::option::Option::None);
}
}
};assert_matches!(meta, MemPlaceMeta::None); // we couldn't store it anyway...
299 // `Place::Local` are always in-bounds of their surrounding local, so we can just
300 // check directly if this remains in-bounds. This cannot actually be violated since
301 // projections are type-checked and bounds-checked.
302if !(offset + layout.size <= self.layout.size) {
::core::panicking::panic("assertion failed: offset + layout.size <= self.layout.size")
};assert!(offset + layout.size <= self.layout.size);
303304// Size `+`, ensures no overflow.
305let new_offset = old_offset.unwrap_or(Size::ZERO) + offset;
306307PlaceTy {
308 place: Place::Local { local, offset: Some(new_offset), locals_addr },
309layout,
310 }
311 }
312 })
313 }
314315#[inline(always)]
316fn to_op<M: Machine<'tcx, Provenance = Prov>>(
317&self,
318 ecx: &InterpCx<'tcx, M>,
319 ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
320ecx.place_to_op(self)
321 }
322}
323324// These are defined here because they produce a place.
325impl<'tcx, Prov: Provenance> OpTy<'tcx, Prov> {
326#[inline(always)]
327pub fn as_mplace_or_imm(&self) -> Either<MPlaceTy<'tcx, Prov>, ImmTy<'tcx, Prov>> {
328match self.op() {
329 Operand::Indirect(mplace) => Left(MPlaceTy { mplace: *mplace, layout: self.layout }),
330 Operand::Immediate(imm) => Right(ImmTy::from_immediate(*imm, self.layout)),
331 }
332 }
333334#[inline(always)]
335 #[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
336pub fn assert_mem_place(&self) -> MPlaceTy<'tcx, Prov> {
337self.as_mplace_or_imm().left().unwrap_or_else(|| {
338bug_impl(None,
format_args!("OpTy of type {0} was immediate when it was expected to be an MPlace",
self.layout.ty), Location::caller())bug!(
339"OpTy of type {} was immediate when it was expected to be an MPlace",
340self.layout.ty
341 )342 })
343 }
344}
345346/// The `Weiteable` trait describes interpreter values that can be written to.
347pub trait Writeable<'tcx, Prov: Provenance>: Projectable<'tcx, Prov> {
348fn to_place(&self) -> PlaceTy<'tcx, Prov>;
349350fn force_mplace<M: Machine<'tcx, Provenance = Prov>>(
351&self,
352 ecx: &mut InterpCx<'tcx, M>,
353 ) -> InterpResult<'tcx, MPlaceTy<'tcx, Prov>>;
354}
355356impl<'tcx, Prov: Provenance> Writeable<'tcx, Prov> for PlaceTy<'tcx, Prov> {
357#[inline(always)]
358fn to_place(&self) -> PlaceTy<'tcx, Prov> {
359self.clone()
360 }
361362#[inline(always)]
363fn force_mplace<M: Machine<'tcx, Provenance = Prov>>(
364&self,
365 ecx: &mut InterpCx<'tcx, M>,
366 ) -> InterpResult<'tcx, MPlaceTy<'tcx, Prov>> {
367ecx.force_allocation(self)
368 }
369}
370371impl<'tcx, Prov: Provenance> Writeable<'tcx, Prov> for MPlaceTy<'tcx, Prov> {
372#[inline(always)]
373fn to_place(&self) -> PlaceTy<'tcx, Prov> {
374self.clone().into()
375 }
376377#[inline(always)]
378fn force_mplace<M: Machine<'tcx, Provenance = Prov>>(
379&self,
380 _ecx: &mut InterpCx<'tcx, M>,
381 ) -> InterpResult<'tcx, MPlaceTy<'tcx, Prov>> {
382interp_ok(self.clone())
383 }
384}
385386// FIXME: Working around https://github.com/rust-lang/rust/issues/54385
387impl<'tcx, Prov, M> InterpCx<'tcx, M>
388where
389Prov: Provenance,
390 M: Machine<'tcx, Provenance = Prov>,
391{
392fn ptr_with_meta_to_mplace(
393&self,
394 ptr: Pointer<Option<M::Provenance>>,
395 meta: MemPlaceMeta<M::Provenance>,
396 layout: TyAndLayout<'tcx>,
397 unaligned: bool,
398 ) -> MPlaceTy<'tcx, M::Provenance> {
399let misaligned =
400if unaligned { None } else { self.is_ptr_misaligned(ptr, layout.align.abi) };
401MPlaceTy { mplace: MemPlace { ptr, meta, misaligned }, layout }
402 }
403404pub fn ptr_to_mplace(
405&self,
406 ptr: Pointer<Option<M::Provenance>>,
407 layout: TyAndLayout<'tcx>,
408 ) -> MPlaceTy<'tcx, M::Provenance> {
409if !layout.is_sized() {
::core::panicking::panic("assertion failed: layout.is_sized()")
};assert!(layout.is_sized());
410self.ptr_with_meta_to_mplace(ptr, MemPlaceMeta::None, layout, /*unaligned*/ false)
411 }
412413pub fn ptr_to_mplace_unaligned(
414&self,
415 ptr: Pointer<Option<M::Provenance>>,
416 layout: TyAndLayout<'tcx>,
417 ) -> MPlaceTy<'tcx, M::Provenance> {
418if !layout.is_sized() {
::core::panicking::panic("assertion failed: layout.is_sized()")
};assert!(layout.is_sized());
419self.ptr_with_meta_to_mplace(ptr, MemPlaceMeta::None, layout, /*unaligned*/ true)
420 }
421422/// Take a value, which represents a (thin or wide) pointer, and make it a place.
423 /// Alignment is just based on the type. This is the inverse of `mplace_to_imm_ptr()`.
424 ///
425 /// Only call this if you are sure the place is "valid" (aligned and inbounds), or do not
426 /// want to ever use the place for memory access!
427 /// Generally prefer `deref_pointer`.
428pub fn imm_ptr_to_mplace(
429&self,
430 val: &ImmTy<'tcx, M::Provenance>,
431 ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
432let pointee_type =
433val.layout.ty.builtin_deref(true).expect("`imm_ptr_to_mplace` called on non-ptr type");
434let layout = self.layout_of(pointee_type)?;
435let (ptr, meta) = val.to_scalar_and_meta();
436437// `imm_ptr_to_mplace` is called on raw pointers even if they don't actually get dereferenced;
438 // we hence can't call `size_and_align_of` since that asserts more validity than we want.
439let ptr = ptr.to_pointer(self);
440interp_ok(self.ptr_with_meta_to_mplace(ptr, meta, layout, /*unaligned*/ false))
441 }
442443/// Turn a mplace into a (thin or wide) mutable raw pointer, pointing to the same space.
444 ///
445 /// `align` information is lost!
446 /// This is the inverse of `imm_ptr_to_mplace`.
447 ///
448 /// If `ptr_ty` is provided, the resulting pointer will be of that type. Otherwise, it defaults to `*mut _`.
449 /// `ptr_ty` must be a type with builtin deref which derefs to the type of `mplace` (`mplace.layout.ty`).
450pub fn mplace_to_imm_ptr(
451&self,
452 mplace: &MPlaceTy<'tcx, M::Provenance>,
453 ptr_ty: Option<Ty<'tcx>>,
454 ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
455let imm = mplace.mplace.to_ref(self);
456457let ptr_ty = ptr_ty458 .inspect(|t| {
match (&t.builtin_deref(true), &Some(mplace.layout.ty)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
}assert_eq!(t.builtin_deref(true), Some(mplace.layout.ty)))
459 .unwrap_or_else(|| Ty::new_mut_ptr(self.tcx.tcx, mplace.layout.ty));
460461let layout = self.layout_of(ptr_ty)?;
462interp_ok(ImmTy::from_immediate(imm, layout))
463 }
464465/// Take an operand, representing a pointer, and dereference it to a place.
466 /// Corresponds to the `*` operator in Rust.
467 /// Unlike `imm_ptr_to_mplace`, this checks that the pointer is valid for its type.
468{}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("deref_pointer",
"rustc_const_eval::interpret::place",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_const_eval/src/interpret/place.rs"),
::tracing_core::__macro_support::Option::Some(468u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::place"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("src")
}> =
::tracing::__macro_support::FieldName::new("src");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&src)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> = loop {};
return __tracing_attr_fake_return;
}
{
let ptr_ty = src.layout().ty;
if !(ptr_ty.is_ref() || ptr_ty.is_raw_ptr() ||
ptr_ty.is_box_global(*self.tcx)) {
bug_impl(None,
format_args!("dereferencing {0}", src.layout().ty),
Location::caller());
}
let val = self.read_immediate(src)?;
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_const_eval/src/interpret/place.rs:480",
"rustc_const_eval::interpret::place",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_const_eval/src/interpret/place.rs"),
::tracing_core::__macro_support::Option::Some(480u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::place"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("deref to {0} on {1:?}",
val.layout.ty, *val) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let mplace = self.imm_ptr_to_mplace(&val)?;
if M::enforce_validity(self, val.layout) {
if ptr_ty.is_ref() || ptr_ty.is_box() {
let kind =
if ptr_ty.is_ref() { "reference" } else { "box" };
let scalar_ptr =
Scalar::from_maybe_pointer(mplace.ptr(), self);
if self.scalar_may_be_null(scalar_ptr)? {
let maybe =
!M::Provenance::OFFSET_IS_ADDR &&
#[allow(non_exhaustive_omitted_patterns)] match scalar_ptr {
Scalar::Ptr(..) => true,
_ => false,
};
do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::Ub(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("dereferencing a {0}null {1}",
if maybe { "maybe-" } else { "" }, kind))
})));
}
let (size, align) =
self.size_and_align_of_val(&mplace)?.unwrap_or_else(||
(mplace.layout.size, mplace.layout.align.abi));
self.check_ptr_access(mplace.ptr(), size,
CheckInAllocMsg::Dereferenceable(kind))?;
self.check_ptr_align(mplace.ptr(),
align).map_err_kind(|err|
{
let ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::AlignmentCheckFailed(Misalignment {
required, has }, _msg)) =
err else {
bug_impl(None, format_args!("impossible case reached"),
Location::caller())
};
::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::Ub(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("encountered an unaligned {2} (required {0} byte alignment but found {1})",
required.bytes(), has.bytes(), kind))
})))
})?;
} else {
if !ptr_ty.is_raw_ptr() {
::core::panicking::panic("assertion failed: ptr_ty.is_raw_ptr()")
};
if mplace.layout.is_unsized() {
let tail =
self.tcx.struct_tail_for_codegen(mplace.layout.ty,
self.typing_env);
match tail.kind() {
ty::Dynamic(data, _) => {
let vtable = mplace.meta().unwrap_meta().to_pointer(self);
self.get_ptr_vtable_ty(vtable, Some(data))?;
}
ty::Slice(..) | ty::Str | ty::Foreign(..) => {}
_ =>
bug_impl(None,
format_args!("Unexpected unsized type tail: {0:?}", tail),
Location::caller()),
}
}
}
}
interp_ok(mplace)
}
}
}#[instrument(skip(self), level = "trace")]469pub fn deref_pointer(
470&self,
471 src: &impl Projectable<'tcx, M::Provenance>,
472 ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
473let ptr_ty = src.layout().ty;
474if !(ptr_ty.is_ref() || ptr_ty.is_raw_ptr() || ptr_ty.is_box_global(*self.tcx)) {
475bug!("dereferencing {}", src.layout().ty);
476 }
477478let val = self.read_immediate(src)?;
479// Construct a place for that pointer.
480trace!("deref to {} on {:?}", val.layout.ty, *val);
481let mplace = self.imm_ptr_to_mplace(&val)?;
482483if M::enforce_validity(self, val.layout) {
484// This is conceptually a typed load from `src` to get the pointer. Most of the time when
485 // we do typed loads for primitive operations, all relevant invariants are checked
486 // implicitly, e.g. when we call `to_bool()` on a Boolean.
487 // But here, we do need to specifically check for metadata validity, null, alignment, and
488 // dereferenceability, or they will not be checked anywhere at all.
489 // This duplicates some of the logic in the validity check, but so far we found no
490 // good way to share that logic.
491if ptr_ty.is_ref() || ptr_ty.is_box() {
492let kind = if ptr_ty.is_ref() { "reference" } else { "box" };
493494// Null check.
495let scalar_ptr = Scalar::from_maybe_pointer(mplace.ptr(), self);
496if self.scalar_may_be_null(scalar_ptr)? {
497let maybe =
498 !M::Provenance::OFFSET_IS_ADDR && matches!(scalar_ptr, Scalar::Ptr(..));
499throw_ub_format!(
500"dereferencing a {maybe}null {kind}",
501 maybe = if maybe { "maybe-" } else { "" }
502 );
503 }
504505// Dereferencability and alignment check. This also implicitly checks metadata validity.
506let (size, align) = self
507.size_and_align_of_val(&mplace)?
508.unwrap_or_else(|| (mplace.layout.size, mplace.layout.align.abi));
509self.check_ptr_access(mplace.ptr(), size, CheckInAllocMsg::Dereferenceable(kind))?;
510self.check_ptr_align(mplace.ptr(), align).map_err_kind(|err| {
511let err_ub!(AlignmentCheckFailed(Misalignment { required, has }, _msg)) = err else { bug!() };
512err_ub_format!(
513"encountered an unaligned {kind} (required {required_bytes} byte alignment but found {found_bytes})",
514 required_bytes = required.bytes(),
515 found_bytes = has.bytes()
516 )
517 })?;
518 } else {
519assert!(ptr_ty.is_raw_ptr());
520// For raw pointers, the validity invariant is pretty weak, but we do require the vtable
521 // to make sense, so we do have to check that if there is one.
522if mplace.layout.is_unsized() {
523let tail = self.tcx.struct_tail_for_codegen(mplace.layout.ty, self.typing_env);
524match tail.kind() {
525 ty::Dynamic(data, _) => {
526let vtable = mplace.meta().unwrap_meta().to_pointer(self);
527self.get_ptr_vtable_ty(vtable, Some(data))?;
528 }
529 ty::Slice(..) | ty::Str | ty::Foreign(..) => {
530// Nothing to check (`read_immediate` already ensured initialization).
531}
532_ => bug!("Unexpected unsized type tail: {:?}", tail),
533 }
534 }
535 }
536 }
537538 interp_ok(mplace)
539 }
540541#[inline]
542pub(super) fn get_place_alloc(
543&self,
544 mplace: &MPlaceTy<'tcx, M::Provenance>,
545 ) -> InterpResult<'tcx, Option<AllocRef<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
546 {
547let (size, _align) = self
548.size_and_align_of_val(mplace)?
549.unwrap_or((mplace.layout.size, mplace.layout.align.abi));
550// We check alignment separately, and *after* checking everything else.
551 // If an access is both OOB and misaligned, we want to see the bounds error.
552let a = self.get_ptr_alloc(mplace.ptr(), size)?;
553self.check_misalign(mplace.mplace.misaligned, CheckAlignMsg::BasedOn)?;
554interp_ok(a)
555 }
556557#[inline]
558pub(super) fn get_place_alloc_mut(
559&mut self,
560 mplace: &MPlaceTy<'tcx, M::Provenance>,
561 ) -> InterpResult<'tcx, Option<AllocRefMut<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
562 {
563let (size, _align) = self
564.size_and_align_of_val(mplace)?
565.unwrap_or((mplace.layout.size, mplace.layout.align.abi));
566// We check alignment separately, and raise that error *after* checking everything else.
567 // If an access is both OOB and misaligned, we want to see the bounds error.
568 // However we have to call `check_misalign` first to make the borrow checker happy.
569let misalign_res = self.check_misalign(mplace.mplace.misaligned, CheckAlignMsg::BasedOn);
570// An error from get_ptr_alloc_mut takes precedence.
571let (a, ()) = self.get_ptr_alloc_mut(mplace.ptr(), size).and(misalign_res)?;
572interp_ok(a)
573 }
574575/// Turn a local in the current frame into a place.
576pub fn local_to_place(
577&self,
578 local: mir::Local,
579 ) -> InterpResult<'tcx, PlaceTy<'tcx, M::Provenance>> {
580let frame = self.frame();
581let layout = self.layout_of_local(frame, local, None)?;
582let place = if layout.is_sized() {
583// We can just always use the `Local` for sized values.
584Place::Local { local, offset: None, locals_addr: frame.locals_addr() }
585 } else {
586// Other parts of the system rely on `Place::Local` never being unsized.
587match frame.locals[local].access()? {
588 Operand::Immediate(_) => bug_impl(None, format_args!("impossible case reached"), Location::caller())bug!(),
589 Operand::Indirect(mplace) => Place::Ptr(*mplace),
590 }
591 };
592interp_ok(PlaceTy { place, layout })
593 }
594595/// Computes a place. You should only use this if you intend to write into this
596 /// place; for reading, a more efficient alternative is `eval_place_to_op`.
597 ///
598 /// If `skip_validity_for_simple_deref` is true, then we do not check validity of the inner
599 /// pointer for places of the form `*ptr`. The caller must justify why that is okay.
600{}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("eval_place",
"rustc_const_eval::interpret::place",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_const_eval/src/interpret/place.rs"),
::tracing_core::__macro_support::Option::Some(600u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::place"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("mir_place")
}> =
::tracing::__macro_support::FieldName::new("mir_place");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("skip_validity_for_simple_deref")
}> =
::tracing::__macro_support::FieldName::new("skip_validity_for_simple_deref");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&mir_place)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&skip_validity_for_simple_deref
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
InterpResult<'tcx, PlaceTy<'tcx, M::Provenance>> = loop {};
return __tracing_attr_fake_return;
}
{
let _trace =
<M as
crate::interpret::Machine>::enter_trace_span(||
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("step",
"rustc_const_eval::interpret::place",
::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_const_eval/src/interpret/place.rs"),
::tracing_core::__macro_support::Option::Some(607u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::place"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("step")
}> =
::tracing::__macro_support::FieldName::new("step");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("mir_place")
}> =
::tracing::__macro_support::FieldName::new("mir_place");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("tracing_separate_thread")
}> =
::tracing::__macro_support::FieldName::new("tracing_separate_thread");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::INFO <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::display(&"eval_place")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&mir_place)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&Empty as
&dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
});
let mut place = self.local_to_place(mir_place.local)?;
if skip_validity_for_simple_deref &&
mir_place.projection.as_slice() ==
&[mir::ProjectionElem::Deref] {
let val = self.read_immediate(&place)?;
let place = self.imm_ptr_to_mplace(&val)?;
return interp_ok(place.into());
}
for elem in mir_place.projection.iter() {
place = self.project(&place, elem)?
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_const_eval/src/interpret/place.rs:623",
"rustc_const_eval::interpret::place",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_const_eval/src/interpret/place.rs"),
::tracing_core::__macro_support::Option::Some(623u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::place"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0:?}",
self.dump_place(&place)) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if true {
let normalized_place_ty =
self.instantiate_from_current_frame_and_normalize_erasing_regions(mir_place.ty(&self.frame().body.local_decls,
*self.tcx).ty)?;
if !mir_assign_valid_types(*self.tcx, self.typing_env,
self.layout_of(normalized_place_ty)?, place.layout) {
bug_impl(Some(self.cur_span()),
format_args!("eval_place of a MIR place with type {0} produced an interpreter place with type {1}",
normalized_place_ty, place.layout.ty), Location::caller())
}
}
interp_ok(place)
}
}
}#[instrument(skip(self), level = "trace")]601pub fn eval_place(
602&self,
603 mir_place: mir::Place<'tcx>,
604 skip_validity_for_simple_deref: bool,
605 ) -> InterpResult<'tcx, PlaceTy<'tcx, M::Provenance>> {
606let _trace =
607enter_trace_span!(M, step::eval_place, ?mir_place, tracing_separate_thread = Empty);
608609let mut place = self.local_to_place(mir_place.local)?;
610if skip_validity_for_simple_deref
611 && mir_place.projection.as_slice() == &[mir::ProjectionElem::Deref]
612 {
613// We want to skip the checks in `deref_pointer`.
614let val = self.read_immediate(&place)?;
615let place = self.imm_ptr_to_mplace(&val)?;
616return interp_ok(place.into());
617 }
618// Using `try_fold` turned out to be bad for performance, hence the loop.
619for elem in mir_place.projection.iter() {
620 place = self.project(&place, elem)?
621}
622623trace!("{:?}", self.dump_place(&place));
624// Sanity-check the type we ended up with.
625if cfg!(debug_assertions) {
626let normalized_place_ty = self
627.instantiate_from_current_frame_and_normalize_erasing_regions(
628 mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty,
629 )?;
630if !mir_assign_valid_types(
631*self.tcx,
632self.typing_env,
633self.layout_of(normalized_place_ty)?,
634 place.layout,
635 ) {
636span_bug!(
637self.cur_span(),
638"eval_place of a MIR place with type {} produced an interpreter place with type {}",
639 normalized_place_ty,
640 place.layout.ty,
641 )
642 }
643 }
644 interp_ok(place)
645 }
646647/// Given a place, returns either the underlying mplace or a reference to where the value of
648 /// this place is stored.
649#[inline(always)]
650fn as_mplace_or_mutable_local(
651&mut self,
652 place: &PlaceTy<'tcx, M::Provenance>,
653 ) -> InterpResult<
654'tcx,
655Either<
656MPlaceTy<'tcx, M::Provenance>,
657 (&mut Immediate<M::Provenance>, TyAndLayout<'tcx>, mir::Local),
658 >,
659 > {
660interp_ok(match place.to_place().as_mplace_or_local() {
661Left(mplace) => Left(mplace),
662Right((local, offset, locals_addr, layout)) => {
663if offset.is_some() {
664// This has been projected to a part of this local, or had the type changed.
665 // FIXME: there are cases where we could still avoid allocating an mplace.
666Left(place.force_mplace(self)?)
667 } else {
668if true {
{
match (&locals_addr, &self.frame().locals_addr()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};debug_assert_eq!(locals_addr, self.frame().locals_addr());
669if true {
{
match (&self.layout_of_local(self.frame(), local, None)?, &layout) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};debug_assert_eq!(self.layout_of_local(self.frame(), local, None)?, layout);
670match self.frame_mut().locals[local].access_mut()? {
671 Operand::Indirect(mplace) => {
672// The local is in memory.
673Left(MPlaceTy { mplace: *mplace, layout })
674 }
675 Operand::Immediate(local_val) => {
676// The local still has the optimized representation.
677Right((local_val, layout, local))
678 }
679 }
680 }
681 }
682 })
683 }
684685/// Write an immediate to a place
686#[inline(always)]
687{}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("write_immediate",
"rustc_const_eval::interpret::place",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_const_eval/src/interpret/place.rs"),
::tracing_core::__macro_support::Option::Some(687u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::place"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("src")
}> =
::tracing::__macro_support::FieldName::new("src");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("dest")
}> =
::tracing::__macro_support::FieldName::new("dest");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&src)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&dest)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: InterpResult<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
self.write_immediate_no_validate(src, dest)?;
if M::enforce_validity(self, dest.layout()) {
self.validate_place(&dest.to_place(),
M::enforce_validity_recursively(self, dest.layout()),
true)?;
}
interp_ok(())
}
}
}#[instrument(skip(self), level = "trace")]688pub fn write_immediate(
689&mut self,
690 src: Immediate<M::Provenance>,
691 dest: &impl Writeable<'tcx, M::Provenance>,
692 ) -> InterpResult<'tcx> {
693self.write_immediate_no_validate(src, dest)?;
694695if M::enforce_validity(self, dest.layout()) {
696// Data got changed, better make sure it matches the type!
697 // Also needed to reset padding.
698self.validate_place(
699&dest.to_place(),
700 M::enforce_validity_recursively(self, dest.layout()),
701/*reset_provenance_and_padding*/ true,
702 )?;
703 }
704705 interp_ok(())
706 }
707708/// Write a scalar to a place
709#[inline(always)]
710pub fn write_scalar(
711&mut self,
712 val: impl Into<Scalar<M::Provenance>>,
713 dest: &impl Writeable<'tcx, M::Provenance>,
714 ) -> InterpResult<'tcx> {
715self.write_immediate(Immediate::Scalar(val.into()), dest)
716 }
717718/// Write a pointer to a place
719#[inline(always)]
720pub fn write_pointer(
721&mut self,
722 ptr: impl Into<Pointer<Option<M::Provenance>>>,
723 dest: &impl Writeable<'tcx, M::Provenance>,
724 ) -> InterpResult<'tcx> {
725self.write_scalar(Scalar::from_maybe_pointer(ptr.into(), self), dest)
726 }
727728/// Write an immediate to a place.
729 /// If you use this you are responsible for validating that things got copied at the
730 /// right type.
731pub(super) fn write_immediate_no_validate(
732&mut self,
733 src: Immediate<M::Provenance>,
734 dest: &impl Writeable<'tcx, M::Provenance>,
735 ) -> InterpResult<'tcx> {
736if !dest.layout().is_sized() {
{
::core::panicking::panic_fmt(format_args!("Cannot write unsized immediate data"));
}
};assert!(dest.layout().is_sized(), "Cannot write unsized immediate data");
737738match self.as_mplace_or_mutable_local(&dest.to_place())? {
739Right((local_val, local_layout, local)) => {
740// Local can be updated in-place.
741*local_val = src;
742// Call the machine hook (the data race detector needs to know about this write).
743if !self.validation_in_progress() {
744 M::after_local_write(self, local, /*storage_live*/ false)?;
745 }
746// Double-check that the value we are storing and the local fit to each other.
747 // Things can ge wrong in quite weird ways when this is violated.
748 // Unfortunately this is too expensive to do in release builds.
749if truecfg!(debug_assertions) {
750src.assert_matches_abi(
751local_layout.backend_repr,
752"invalid immediate for given destination place",
753self,
754 );
755 }
756 }
757Left(mplace) => {
758self.write_immediate_to_mplace_no_validate(src, mplace.layout, mplace.mplace)?;
759 }
760 }
761interp_ok(())
762 }
763764/// Write an immediate to memory.
765 /// If you use this you are responsible for validating that things got copied at the
766 /// right layout.
767fn write_immediate_to_mplace_no_validate(
768&mut self,
769 value: Immediate<M::Provenance>,
770 layout: TyAndLayout<'tcx>,
771 dest: MemPlace<M::Provenance>,
772 ) -> InterpResult<'tcx> {
773// We use the sizes from `value` below.
774 // Ensure that matches the type of the place it is written to.
775value.assert_matches_abi(
776layout.backend_repr,
777"invalid immediate for given destination place",
778self,
779 );
780// Note that it is really important that the type here is the right one, and matches the
781 // type things are read at. In case `value` is a `ScalarPair`, we don't do any magic here
782 // to handle padding properly, which is only correct if we never look at this data with the
783 // wrong type.
784785let will_later_validate = M::enforce_validity(self, layout);
786let Some(mut alloc) = self.get_place_alloc_mut(&MPlaceTy { mplace: dest, layout })? else {
787// zero-sized access
788return interp_ok(());
789 };
790791match value {
792 Immediate::Scalar(scalar) => {
793 alloc.write_scalar(alloc_range(Size::ZERO, scalar.size()), scalar)?;
794 }
795 Immediate::ScalarPair(a_val, b_val) => {
796let BackendRepr::ScalarPair { a: _, b: _, b_offset } = layout.backend_repr else {
797bug_impl(Some(self.cur_span()),
format_args!("write_immediate_to_mplace: invalid ScalarPair layout: {0:#?}",
layout), Location::caller())span_bug!(
798self.cur_span(),
799"write_immediate_to_mplace: invalid ScalarPair layout: {:#?}",
800 layout
801 )802 };
803let a_size = a_val.size();
804let b_size = b_val.size();
805if !(b_offset.bytes() > 0) {
::core::panicking::panic("assertion failed: b_offset.bytes() > 0")
};assert!(b_offset.bytes() > 0); // in `operand_field` we use the offset to tell apart the fields
806807 // It is tempting to verify `b_offset` against `layout.fields.offset(1)`,
808 // but that does not work: We could be a newtype around a pair, then the
809 // fields do not match the `ScalarPair` components.
810811 // In preparation, if we do *not* later reset the padding, we clear the entire
812 // destination now to ensure that no stray pointer fragments are being
813 // preserved (see <https://github.com/rust-lang/rust/issues/148470>).
814 // We can skip this if there is no padding (e.g. for wide pointers).
815if !will_later_validate && a_size + b_size != layout.size {
816alloc.write_uninit_full();
817 }
818819 alloc.write_scalar(alloc_range(Size::ZERO, a_size), a_val)?;
820 alloc.write_scalar(alloc_range(b_offset, b_size), b_val)?;
821 }
822 Immediate::Uninit => alloc.write_uninit_full(),
823 }
824interp_ok(())
825 }
826827pub fn write_uninit(
828&mut self,
829 dest: &impl Writeable<'tcx, M::Provenance>,
830 ) -> InterpResult<'tcx> {
831match self.as_mplace_or_mutable_local(&dest.to_place())? {
832Right((local_val, _local_layout, local)) => {
833*local_val = Immediate::Uninit;
834// Call the machine hook (the data race detector needs to know about this write).
835if !self.validation_in_progress() {
836 M::after_local_write(self, local, /*storage_live*/ false)?;
837 }
838 }
839Left(mplace) => {
840let Some(mut alloc) = self.get_place_alloc_mut(&mplace)? else {
841// Zero-sized access
842return interp_ok(());
843 };
844alloc.write_uninit_full();
845 }
846 }
847interp_ok(())
848 }
849850/// Remove all provenance in the given place.
851pub fn clear_provenance(
852&mut self,
853 dest: &impl Writeable<'tcx, M::Provenance>,
854 ) -> InterpResult<'tcx> {
855// If this is an efficiently represented local variable without provenance, skip the
856 // `as_mplace_or_mutable_local` that would otherwise force this local into memory.
857if let Right(imm) = dest.to_op(self)?.as_mplace_or_imm() {
858if !imm.has_provenance() {
859return interp_ok(());
860 }
861 }
862match self.as_mplace_or_mutable_local(&dest.to_place())? {
863Right((local_val, _local_layout, local)) => {
864 local_val.clear_provenance()?;
865// Call the machine hook (the data race detector needs to know about this write).
866if !self.validation_in_progress() {
867 M::after_local_write(self, local, /*storage_live*/ false)?;
868 }
869 }
870Left(mplace) => {
871let Some(mut alloc) = self.get_place_alloc_mut(&mplace)? else {
872// Zero-sized access
873return interp_ok(());
874 };
875alloc.clear_provenance();
876 }
877 }
878interp_ok(())
879 }
880881/// Copies the data from an operand to a place.
882 /// The layouts of the `src` and `dest` may disagree.
883#[inline(always)]
884pub fn copy_op_allow_transmute(
885&mut self,
886 src: &impl Projectable<'tcx, M::Provenance>,
887 dest: &impl Writeable<'tcx, M::Provenance>,
888 ) -> InterpResult<'tcx> {
889self.copy_op_inner(src, dest, /* allow_transmute */ true)
890 }
891892/// Copies the data from an operand to a place.
893 /// `src` and `dest` must have the same layout and the copied value will be validated.
894#[inline(always)]
895pub fn copy_op(
896&mut self,
897 src: &impl Projectable<'tcx, M::Provenance>,
898 dest: &impl Writeable<'tcx, M::Provenance>,
899 ) -> InterpResult<'tcx> {
900self.copy_op_inner(src, dest, /* allow_transmute */ false)
901 }
902903/// Perform a typed copy of the data from an operand to a place.
904 ///
905 /// `allow_transmute` indicates whether the layouts may disagree. In that case there are
906 /// technically *two* typed copies: `src` is a not-yet-loaded value, so we're doing a typed copy
907 /// at `src` type from there to some intermediate storage. And then we're doing a second typed
908 /// copy at `dest` type from that intermediate storage to `dest`. As an optimization, we only
909 /// make a single direct copy here, but we still have to ensure the data is valid at both types.
910#[inline(always)]
911{}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("copy_op_inner",
"rustc_const_eval::interpret::place",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_const_eval/src/interpret/place.rs"),
::tracing_core::__macro_support::Option::Some(911u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::place"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("src")
}> =
::tracing::__macro_support::FieldName::new("src");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("dest")
}> =
::tracing::__macro_support::FieldName::new("dest");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("allow_transmute")
}> =
::tracing::__macro_support::FieldName::new("allow_transmute");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&src)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&dest)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&allow_transmute
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: InterpResult<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
self.copy_op_no_validate(src, dest, allow_transmute)?;
if M::enforce_validity(self, dest.layout()) {
let dest = dest.to_place();
if src.layout().ty != dest.layout().ty {
self.validate_place(&dest.transmute(src.layout(), self)?,
M::enforce_validity_recursively(self, src.layout()), true)?;
}
self.validate_place(&dest,
M::enforce_validity_recursively(self, dest.layout()),
true)?;
}
interp_ok(())
}
}
}#[instrument(skip(self), level = "trace")]912fn copy_op_inner(
913&mut self,
914 src: &impl Projectable<'tcx, M::Provenance>,
915 dest: &impl Writeable<'tcx, M::Provenance>,
916 allow_transmute: bool,
917 ) -> InterpResult<'tcx> {
918// Do the actual copy.
919self.copy_op_no_validate(src, dest, allow_transmute)?;
920921if M::enforce_validity(self, dest.layout()) {
922let dest = dest.to_place();
923// Given that there were two typed copies, we have to ensure this is valid at both
924 // types, and we have to ensure this loses provenance and padding according to both
925 // types. We also transmute both ways: when transmuting `*ptr` from `&T` to `*const T`,
926 // it seems nice to ensure that the resulting pointer value indeed is derived from a
927 // shared reference.
928 // But if the types are identical, that is strictly redundant so we only do one pass.
929if src.layout().ty != dest.layout().ty {
930self.validate_place(
931&dest.transmute(src.layout(), self)?,
932 M::enforce_validity_recursively(self, src.layout()),
933/*reset_provenance_and_padding*/ true,
934 )?;
935 }
936self.validate_place(
937&dest,
938 M::enforce_validity_recursively(self, dest.layout()),
939/*reset_provenance_and_padding*/ true,
940 )?;
941 }
942943 interp_ok(())
944 }
945946/// Perform an untyped copy of the data from an operand to a place.
947 /// You are responsible for validating that things get copied at the right type.
948 ///
949 /// `allow_transmute` indicates whether the layouts may disagree.
950{}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("copy_op_no_validate",
"rustc_const_eval::interpret::place",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_const_eval/src/interpret/place.rs"),
::tracing_core::__macro_support::Option::Some(950u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::place"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("src")
}> =
::tracing::__macro_support::FieldName::new("src");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("dest")
}> =
::tracing::__macro_support::FieldName::new("dest");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("allow_transmute")
}> =
::tracing::__macro_support::FieldName::new("allow_transmute");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&src)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&dest)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&allow_transmute
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: InterpResult<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let layout_compat =
mir_assign_valid_types(*self.tcx, self.typing_env,
src.layout(), dest.layout());
if !allow_transmute && !layout_compat {
bug_impl(Some(self.cur_span()),
format_args!("type mismatch when copying!\nsrc: {0},\ndest: {1}",
src.layout().ty, dest.layout().ty), Location::caller());
}
let src_has_padding =
match src.layout().backend_repr {
BackendRepr::Scalar(_) => false,
BackendRepr::ScalarPair { a: left, b: right, b_offset: _ }
if
#[allow(non_exhaustive_omitted_patterns)] match src.layout().ty.kind()
{
ty::Ref(..) | ty::RawPtr(..) => true,
_ => false,
} => {
if true {
{
match (&(left.size(self) + right.size(self)),
&src.layout().size) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};
false
}
BackendRepr::ScalarPair { a: left, b: right, b_offset: _ }
=> {
let left_size = left.size(self);
let right_size = right.size(self);
left_size + right_size != src.layout().size
}
BackendRepr::SimdVector { .. } |
BackendRepr::SimdScalableVector { .. } |
BackendRepr::Memory { .. } => true,
};
let src_val =
if src_has_padding {
src.to_op(self)?.as_mplace_or_imm()
} else { self.read_immediate_raw(src)? };
let src =
match src_val {
Right(src_val) => {
if !!src.layout().is_unsized() {
::core::panicking::panic("assertion failed: !src.layout().is_unsized()")
};
if !!dest.layout().is_unsized() {
::core::panicking::panic("assertion failed: !dest.layout().is_unsized()")
};
{
match (&src.layout().size, &dest.layout().size) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
return if layout_compat {
self.write_immediate_no_validate(*src_val, dest)
} else {
let dest_mem = dest.force_mplace(self)?;
self.write_immediate_to_mplace_no_validate(*src_val,
src.layout(), dest_mem.mplace)
};
}
Left(mplace) => mplace,
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_const_eval/src/interpret/place.rs:1026",
"rustc_const_eval::interpret::place",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_const_eval/src/interpret/place.rs"),
::tracing_core::__macro_support::Option::Some(1026u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::place"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("copy_op: {0:?} <- {1:?}: {2}",
*dest, src, dest.layout().ty) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
let dest = dest.force_mplace(self)?;
let Some((dest_size, _)) =
self.size_and_align_of_val(&dest)? else {
bug_impl(Some(self.cur_span()),
format_args!("copy_op needs (dynamically) sized values"),
Location::caller())
};
if true {
let src_size = self.size_and_align_of_val(&src)?.unwrap().0;
{
match (&src_size, &dest_size) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("Cannot copy differently-sized data")));
}
}
}
};
} else {
{
match (&src.layout.size, &dest.layout.size) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
}
self.mem_copy(src.ptr(), dest.ptr(), dest_size, true)?;
self.check_misalign(src.mplace.misaligned,
CheckAlignMsg::BasedOn)?;
self.check_misalign(dest.mplace.misaligned,
CheckAlignMsg::BasedOn)?;
interp_ok(())
}
}
}#[instrument(skip(self), level = "trace")]951pub(super) fn copy_op_no_validate(
952&mut self,
953 src: &impl Projectable<'tcx, M::Provenance>,
954 dest: &impl Writeable<'tcx, M::Provenance>,
955 allow_transmute: bool,
956 ) -> InterpResult<'tcx> {
957// We do NOT compare the types for equality, because well-typed code can
958 // actually "transmute" `&mut T` to `&T` in an assignment without a cast.
959let layout_compat =
960 mir_assign_valid_types(*self.tcx, self.typing_env, src.layout(), dest.layout());
961if !allow_transmute && !layout_compat {
962span_bug!(
963self.cur_span(),
964"type mismatch when copying!\nsrc: {},\ndest: {}",
965 src.layout().ty,
966 dest.layout().ty,
967 );
968 }
969// If the source has padding, we want to always do a mem-to-mem copy to ensure consistent
970 // padding in the target independent of layout choices.
971let src_has_padding = match src.layout().backend_repr {
972 BackendRepr::Scalar(_) => false,
973 BackendRepr::ScalarPair { a: left, b: right, b_offset: _ }
974if matches!(src.layout().ty.kind(), ty::Ref(..) | ty::RawPtr(..)) =>
975 {
976// Wide pointers never have padding, so we can avoid calling `size()`.
977debug_assert_eq!(left.size(self) + right.size(self), src.layout().size);
978false
979}
980 BackendRepr::ScalarPair { a: left, b: right, b_offset: _ } => {
981let left_size = left.size(self);
982let right_size = right.size(self);
983// We have padding if the sizes don't add up to the total.
984 // (Why don't we need to check the offset? The scalars don't overlap so no padding
985 // implies `b_offset == left_size`, which would be superfluous to check explicitly.)
986left_size + right_size != src.layout().size
987 }
988// Everything else can only exist in memory anyway, so it doesn't matter.
989BackendRepr::SimdVector { .. }
990 | BackendRepr::SimdScalableVector { .. }
991 | BackendRepr::Memory { .. } => true,
992 };
993994let src_val = if src_has_padding {
995// Do our best to get an mplace. If there's no mplace, then this is stored as an
996 // "optimized" local, so its padding is definitely uninitialized and we are fine.
997src.to_op(self)?.as_mplace_or_imm()
998 } else {
999// Do our best to get an immediate, to avoid having to force_allocate the destination.
1000self.read_immediate_raw(src)?
1001};
1002let src = match src_val {
1003 Right(src_val) => {
1004assert!(!src.layout().is_unsized());
1005assert!(!dest.layout().is_unsized());
1006assert_eq!(src.layout().size, dest.layout().size);
1007// Yay, we got a value that we can write directly.
1008return if layout_compat {
1009self.write_immediate_no_validate(*src_val, dest)
1010 } else {
1011// This is tricky. The problematic case is `ScalarPair`: the `src_val` was
1012 // loaded using the offsets defined by `src.layout`. When we put this back into
1013 // the destination, we have to use the same offsets! So (a) we make sure we
1014 // write back to memory, and (b) we use `dest` *with the source layout*.
1015let dest_mem = dest.force_mplace(self)?;
1016self.write_immediate_to_mplace_no_validate(
1017*src_val,
1018 src.layout(),
1019 dest_mem.mplace,
1020 )
1021 };
1022 }
1023 Left(mplace) => mplace,
1024 };
1025// Slow path, this does not fit into an immediate. Just memcpy.
1026trace!("copy_op: {:?} <- {:?}: {}", *dest, src, dest.layout().ty);
10271028let dest = dest.force_mplace(self)?;
1029let Some((dest_size, _)) = self.size_and_align_of_val(&dest)? else {
1030span_bug!(self.cur_span(), "copy_op needs (dynamically) sized values")
1031 };
1032if cfg!(debug_assertions) {
1033let src_size = self.size_and_align_of_val(&src)?.unwrap().0;
1034assert_eq!(src_size, dest_size, "Cannot copy differently-sized data");
1035 } else {
1036// As a cheap approximation, we compare the fixed parts of the size.
1037assert_eq!(src.layout.size, dest.layout.size);
1038 }
10391040// Setting `nonoverlapping` here only has an effect when we don't hit the fast-path above,
1041 // but that should at least match what LLVM does where `memcpy` is also only used when the
1042 // type does not have Scalar/ScalarPair layout.
1043 // (Or as the `Assign` docs put it, assignments "not producing primitives" must be
1044 // non-overlapping.)
1045 // We check alignment separately, and *after* checking everything else.
1046 // If an access is both OOB and misaligned, we want to see the bounds error.
1047self.mem_copy(src.ptr(), dest.ptr(), dest_size, /*nonoverlapping*/ true)?;
1048self.check_misalign(src.mplace.misaligned, CheckAlignMsg::BasedOn)?;
1049self.check_misalign(dest.mplace.misaligned, CheckAlignMsg::BasedOn)?;
1050 interp_ok(())
1051 }
10521053/// Ensures that a place is in memory, and returns where it is.
1054 /// If the place currently refers to a local that doesn't yet have a matching allocation,
1055 /// create such an allocation.
1056 /// This is essentially `force_to_memplace`.
1057{}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("force_allocation",
"rustc_const_eval::interpret::place",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_const_eval/src/interpret/place.rs"),
::tracing_core::__macro_support::Option::Some(1057u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::place"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("place")
}> =
::tracing::__macro_support::FieldName::new("place");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> = loop {};
return __tracing_attr_fake_return;
}
{
let mplace =
match place.place {
Place::Local { local, offset, locals_addr } => {
if true {
{
match (&locals_addr, &self.frame().locals_addr()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};
let whole_local =
match self.frame_mut().locals[local].access_mut()? {
&mut Operand::Immediate(local_val) => {
let local_layout =
self.layout_of_local(&self.frame(), local, None)?;
if !local_layout.is_sized() {
{
::core::panicking::panic_fmt(format_args!("unsized locals cannot be immediate"));
}
};
let mplace =
self.allocate(local_layout, MemoryKind::Stack)?;
if !#[allow(non_exhaustive_omitted_patterns)] match local_val
{
Immediate::Uninit => true,
_ => false,
} {
self.write_immediate_to_mplace_no_validate(local_val,
local_layout, mplace.mplace)?;
}
M::after_local_moved_to_memory(self, local, &mplace)?;
*self.frame_mut().locals[local].access_mut().unwrap() =
Operand::Indirect(mplace.mplace);
mplace.mplace
}
&mut Operand::Indirect(mplace) => mplace,
};
if let Some(offset) = offset {
whole_local.offset_with_meta_(offset, OffsetMode::Wrapping,
MemPlaceMeta::None, self)?
} else { whole_local }
}
Place::Ptr(mplace) => mplace,
};
interp_ok(MPlaceTy { mplace, layout: place.layout })
}
}
}#[instrument(skip(self), level = "trace")]1058pub fn force_allocation(
1059&mut self,
1060 place: &PlaceTy<'tcx, M::Provenance>,
1061 ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
1062let mplace = match place.place {
1063 Place::Local { local, offset, locals_addr } => {
1064debug_assert_eq!(locals_addr, self.frame().locals_addr());
1065let whole_local = match self.frame_mut().locals[local].access_mut()? {
1066&mut Operand::Immediate(local_val) => {
1067// We need to make an allocation.
10681069 // We need the layout of the local. We can NOT use the layout we got,
1070 // that might e.g., be an inner field of a struct with `Scalar` layout,
1071 // that has different alignment than the outer field.
1072let local_layout = self.layout_of_local(&self.frame(), local, None)?;
1073assert!(local_layout.is_sized(), "unsized locals cannot be immediate");
1074let mplace = self.allocate(local_layout, MemoryKind::Stack)?;
1075// Preserve old value. (As an optimization, we can skip this if it was uninit.)
1076if !matches!(local_val, Immediate::Uninit) {
1077// We don't have to validate as we can assume the local was already
1078 // valid for its type. We must not use any part of `place` here, that
1079 // could be a projection to a part of the local!
1080self.write_immediate_to_mplace_no_validate(
1081 local_val,
1082 local_layout,
1083 mplace.mplace,
1084 )?;
1085 }
1086 M::after_local_moved_to_memory(self, local, &mplace)?;
1087// Now we can call `access_mut` again, asserting it goes well, and actually
1088 // overwrite things. This points to the entire allocation, not just the part
1089 // the place refers to, i.e. we do this before we apply `offset`.
1090*self.frame_mut().locals[local].access_mut().unwrap() =
1091 Operand::Indirect(mplace.mplace);
1092 mplace.mplace
1093 }
1094&mut Operand::Indirect(mplace) => mplace, // this already was an indirect local
1095};
1096if let Some(offset) = offset {
1097// This offset is always inbounds, no need to check it again.
1098whole_local.offset_with_meta_(
1099 offset,
1100 OffsetMode::Wrapping,
1101 MemPlaceMeta::None,
1102self,
1103 )?
1104} else {
1105// Preserve wide place metadata, do not call `offset`.
1106whole_local
1107 }
1108 }
1109 Place::Ptr(mplace) => mplace,
1110 };
1111// Return with the original layout and align, so that the caller can go on
1112interp_ok(MPlaceTy { mplace, layout: place.layout })
1113 }
11141115pub fn allocate_dyn(
1116&mut self,
1117 layout: TyAndLayout<'tcx>,
1118 kind: MemoryKind<M::MemoryKind>,
1119 meta: MemPlaceMeta<M::Provenance>,
1120 ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
1121let Some((size, align)) = self.size_and_align_from_meta(&meta, &layout)? else {
1122bug_impl(Some(self.cur_span()),
format_args!("cannot allocate space for `extern` type, size is not known"),
Location::caller())span_bug!(self.cur_span(), "cannot allocate space for `extern` type, size is not known")1123 };
1124let ptr = self.allocate_ptr(size, align, kind, AllocInit::Uninit)?;
1125interp_ok(self.ptr_with_meta_to_mplace(ptr.into(), meta, layout, /*unaligned*/ false))
1126 }
11271128pub fn allocate(
1129&mut self,
1130 layout: TyAndLayout<'tcx>,
1131 kind: MemoryKind<M::MemoryKind>,
1132 ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
1133if !layout.is_sized() {
::core::panicking::panic("assertion failed: layout.is_sized()")
};assert!(layout.is_sized());
1134self.allocate_dyn(layout, kind, MemPlaceMeta::None)
1135 }
11361137/// Allocates a sequence of bytes in the interpreter's memory with alignment 1.
1138 /// This is allocated in immutable global memory and deduplicated.
1139pub fn allocate_bytes_dedup(
1140&mut self,
1141 bytes: &[u8],
1142 ) -> InterpResult<'tcx, Pointer<M::Provenance>> {
1143let salt = M::get_global_alloc_salt(self, None);
1144let id = self.tcx.allocate_bytes_dedup(bytes, salt);
11451146// Turn untagged "global" pointers (obtained via `tcx`) into the machine pointer to the allocation.
1147M::adjust_alloc_root_pointer(
1148&self,
1149Pointer::from(id),
1150 M::GLOBAL_KIND.map(MemoryKind::Machine),
1151 )
1152 }
11531154/// Allocates a string in the interpreter's memory, returning it as a (wide) place.
1155 /// This is allocated in immutable global memory and deduplicated.
1156pub fn allocate_str_dedup(
1157&mut self,
1158 s: &str,
1159 ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
1160let bytes = s.as_bytes();
1161let ptr = self.allocate_bytes_dedup(bytes)?;
11621163// Create length metadata for the string.
1164let meta = Scalar::from_target_usize(u64::try_from(bytes.len()).unwrap(), self);
11651166// Get layout for Rust's str type.
1167let layout = self.layout_of(self.tcx.types.str_).unwrap();
11681169// Combine pointer and metadata into a wide pointer.
1170interp_ok(self.ptr_with_meta_to_mplace(
1171ptr.into(),
1172 MemPlaceMeta::Meta(meta),
1173layout,
1174/*unaligned*/ false,
1175 ))
1176 }
11771178pub fn raw_const_to_mplace(
1179&self,
1180 raw: mir::ConstAlloc<'tcx>,
1181 ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
1182// This must be an allocation in `tcx`
1183let _ = self.tcx.global_alloc(raw.alloc_id);
1184let ptr = self.global_root_pointer(Pointer::from(raw.alloc_id))?;
1185let layout = self.layout_of(raw.ty)?;
1186interp_ok(self.ptr_to_mplace(ptr.into(), layout))
1187 }
1188}
11891190// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
1191#[cfg(target_pointer_width = "64")]
1192mod size_asserts {
1193use rustc_data_structures::static_assert_size;
11941195use super::*;
1196// tidy-alphabetical-start
1197const _: [(); 64] = [(); ::std::mem::size_of::<MPlaceTy<'_>>()];static_assert_size!(MPlaceTy<'_>, 64);
1198const _: [(); 48] = [(); ::std::mem::size_of::<MemPlace>()];static_assert_size!(MemPlace, 48);
1199const _: [(); 24] = [(); ::std::mem::size_of::<MemPlaceMeta>()];static_assert_size!(MemPlaceMeta, 24);
1200const _: [(); 48] = [(); ::std::mem::size_of::<Place>()];static_assert_size!(Place, 48);
1201const _: [(); 64] = [(); ::std::mem::size_of::<PlaceTy<'_>>()];static_assert_size!(PlaceTy<'_>, 64);
1202// tidy-alphabetical-end
1203}