Skip to content

Commit 2b43980

Browse files
authoredDec 13, 2020
Rollup merge of #79942 - JCTyblaidd:static-mem-init, r=RalfJung
Add post-init hook for static memory for miri. Adds a post-initialization hook to treat memory initialized using the interpreter as if it was initialized in a static context. See: rust-lang/miri#1644 & rust-lang/miri#1643
2 parents 1b81f08 + 175226a commit 2b43980

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed
 

‎compiler/rustc_mir/src/interpret/machine.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::hash::Hash;
99
use rustc_middle::mir;
1010
use rustc_middle::ty::{self, Ty};
1111
use rustc_span::def_id::DefId;
12+
use rustc_target::abi::Size;
1213

1314
use super::{
1415
AllocId, Allocation, AllocationExtra, CheckInAllocMsg, Frame, ImmTy, InterpCx, InterpResult,
@@ -299,6 +300,15 @@ pub trait Machine<'mir, 'tcx>: Sized {
299300
Ok(())
300301
}
301302

303+
/// Called after initializing static memory using the interpreter.
304+
fn after_static_mem_initialized(
305+
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
306+
_ptr: Pointer<Self::PointerTag>,
307+
_size: Size,
308+
) -> InterpResult<'tcx> {
309+
Ok(())
310+
}
311+
302312
/// Executes a retagging operation
303313
#[inline]
304314
fn retag(

‎compiler/rustc_mir/src/interpret/traits.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5656
// If you touch this code, be sure to also make the corresponding changes to
5757
// `get_vtable` in `rust_codegen_llvm/meth.rs`.
5858
// /////////////////////////////////////////////////////////////////////////////////////////
59-
let vtable = self.memory.allocate(
60-
ptr_size * u64::try_from(methods.len()).unwrap().checked_add(3).unwrap(),
61-
ptr_align,
62-
MemoryKind::Vtable,
63-
);
59+
let vtable_size = ptr_size * u64::try_from(methods.len()).unwrap().checked_add(3).unwrap();
60+
let vtable = self.memory.allocate(vtable_size, ptr_align, MemoryKind::Vtable);
6461

6562
let drop = Instance::resolve_drop_in_place(tcx, ty);
6663
let drop = self.memory.create_fn_alloc(FnVal::Instance(drop));
@@ -93,6 +90,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9390
}
9491
}
9592

93+
M::after_static_mem_initialized(self, vtable, vtable_size)?;
94+
9695
self.memory.mark_immutable(vtable.alloc_id)?;
9796
assert!(self.vtables.insert((ty, poly_trait_ref), vtable).is_none());
9897

0 commit comments

Comments
 (0)
Please sign in to comment.