Skip to content

Commit 56d8936

Browse files
committed
Add post-initialization hook for static memory initialized using the interpereter.
1 parent a9f7d19 commit 56d8936

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ 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_size = ptr_size * u64::try_from(methods.len()).unwrap().checked_add(3).unwrap();
5960
let vtable = self.memory.allocate(
60-
ptr_size * u64::try_from(methods.len()).unwrap().checked_add(3).unwrap(),
61+
vtable_size,
6162
ptr_align,
6263
MemoryKind::Vtable,
6364
);
@@ -93,6 +94,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9394
}
9495
}
9596

97+
M::after_static_mem_initialized(self, vtable, vtable_size)?;
98+
9699
self.memory.mark_immutable(vtable.alloc_id)?;
97100
assert!(self.vtables.insert((ty, poly_trait_ref), vtable).is_none());
98101

0 commit comments

Comments
 (0)