diff --git a/src/interpreter.rs b/src/interpreter.rs index 145d3d30808d..5e45e717dfeb 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -10,7 +10,7 @@ use std::ops::Deref; use std::rc::Rc; use error::EvalResult; -use memory::{FieldRepr, Memory, Pointer, Repr}; +use memory::{self, FieldRepr, Memory, Pointer, Repr}; use primval::{self, PrimVal}; const TRACE_EXECUTION: bool = true; @@ -319,6 +319,12 @@ impl<'a, 'tcx: 'a> Interpreter<'a, 'tcx> { self.memory.write_ptr(dest, ptr) } + Box(ty) => { + let repr = self.ty_to_repr(ty); + let ptr = self.memory.allocate(repr.size()); + self.memory.write_ptr(dest, ptr) + } + ref r => panic!("can't handle rvalue: {:?}", r), } } @@ -476,7 +482,7 @@ impl<'a, 'tcx: 'a> Interpreter<'a, 'tcx> { self.make_variant_repr(&adt_def.variants[0], substs) } - ty::TyRef(_, ty::TypeAndMut { ty, .. }) => { + ty::TyRef(_, ty::TypeAndMut { ty, .. }) | ty::TyBox(ty) => { Repr::Pointer { target: Box::new(self.ty_to_repr(ty)) } } @@ -523,6 +529,15 @@ impl<'mir, 'tcx: 'mir> Deref for CachedMir<'mir, 'tcx> { } pub fn interpret_start_points<'tcx>(tcx: &TyCtxt<'tcx>, mir_map: &MirMap<'tcx>) { + /// Print the given allocation and all allocations it depends on. + fn print_allocation_tree(memory: &Memory, alloc_id: memory::AllocId) { + let alloc = memory.get(alloc_id).unwrap(); + println!(" {:?}", alloc); + for &target_alloc in alloc.relocations.values() { + print_allocation_tree(memory, target_alloc); + } + } + for (&id, mir) in &mir_map.map { for attr in tcx.map.attrs(id) { use syntax::attr::AttrMetaMethods; @@ -543,7 +558,8 @@ pub fn interpret_start_points<'tcx>(tcx: &TyCtxt<'tcx>, mir_map: &MirMap<'tcx>) miri.run().unwrap(); if let Some(ret) = return_ptr { - println!("Returned: {:?}\n", miri.memory.get(ret.alloc_id).unwrap()); + println!("Result:"); + print_allocation_tree(&miri.memory, ret.alloc_id); } } } diff --git a/src/memory.rs b/src/memory.rs index 8a962d804b7b..3675476e2ee1 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -16,16 +16,6 @@ pub struct Memory { #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct AllocId(u64); -/// A relocation represents a part of an allocation which points into another allocation. This is -/// used to represent pointers existing in the virtual memory. -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub struct Relocation { - /// The offset in the allocation where the relocation starts. - offset: usize, - /// The allocation this relocation points into. - target: AllocId, -} - #[derive(Debug)] pub struct Allocation { pub bytes: Vec, diff --git a/test/heap.rs b/test/heap.rs new file mode 100755 index 000000000000..c97633c65698 --- /dev/null +++ b/test/heap.rs @@ -0,0 +1,7 @@ +#![feature(custom_attribute)] +#![allow(dead_code, unused_attributes)] + +#[miri_run] +fn make_box() -> Box { + Box::new(42) +}