diff options
| author | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2017-08-28 16:13:09 +0200 |
|---|---|---|
| committer | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2017-08-28 16:13:09 +0200 |
| commit | dd5b0100f3272c1a9437e841363ea1ed1609979c (patch) | |
| tree | aae84114a11e7baf1c825c3845ce7477fce244bd | |
| parent | 2f0dcfba1d7fd007af1d9d9cfb92bf67ec151f7e (diff) | |
| parent | 44a360d8ba3cd77e86fcb510808e2b1c550d4c46 (diff) | |
| download | rust-dd5b0100f3272c1a9437e841363ea1ed1609979c.tar.gz rust-dd5b0100f3272c1a9437e841363ea1ed1609979c.zip | |
Merge remote-tracking branch 'origin/master' into memory
| -rw-r--r-- | miri/lib.rs | 9 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/memory.rs | 38 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/mod.rs | 2 | ||||
| -rw-r--r-- | tests/compile-fail/memleak_rc.rs | 3 | ||||
| -rw-r--r-- | tests/compile-fail/panic.rs | 3 | ||||
| -rw-r--r-- | tests/compile-fail/zst2.rs | 3 | ||||
| -rw-r--r-- | tests/compile-fail/zst3.rs | 3 | ||||
| -rw-r--r-- | tests/run-pass/btreemap.rs | 17 | ||||
| -rw-r--r-- | tests/run-pass/rc.rs | 3 | ||||
| -rw-r--r-- | tests/run-pass/send-is-not-static-par-for.rs | 3 | ||||
| -rw-r--r-- | tests/run-pass/std.rs | 3 |
11 files changed, 41 insertions, 46 deletions
diff --git a/miri/lib.rs b/miri/lib.rs index 204746244c8..852a4cbe2aa 100644 --- a/miri/lib.rs +++ b/miri/lib.rs @@ -6,11 +6,8 @@ // From rustc. #[macro_use] extern crate log; -extern crate log_settings; #[macro_use] extern crate rustc; -extern crate rustc_const_math; -extern crate rustc_data_structures; extern crate syntax; use rustc::ty::{self, TyCtxt}; @@ -146,9 +143,9 @@ pub fn eval_main<'a, 'tcx: 'a>( } } -struct Evaluator; +pub struct Evaluator; #[derive(Default)] -struct EvaluatorData { +pub struct EvaluatorData { /// Environment variables set by `setenv` /// Miri does not expose env vars from the host to the emulated program pub(crate) env_vars: HashMap<Vec<u8>, MemoryPointer>, @@ -163,7 +160,7 @@ pub struct TlsEntry<'tcx> { } #[derive(Default)] -struct MemoryData<'tcx> { +pub struct MemoryData<'tcx> { /// The Key to use for the next thread-local allocation. next_thread_local: TlsKey, diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index adca51acba6..e1a0a7d3659 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -79,7 +79,7 @@ impl LockInfo { pub struct AllocId(u64); #[derive(Debug)] -enum AllocIdKind { +pub enum AllocIdKind { /// We can't ever have more than `usize::max_value` functions at the same time /// since we never "deallocate" functions Function(usize), @@ -89,7 +89,7 @@ enum AllocIdKind { } impl AllocIdKind { - fn into_alloc_id(self) -> AllocId { + pub fn into_alloc_id(self) -> AllocId { match self { AllocIdKind::Function(n) => AllocId(n as u64), AllocIdKind::Runtime(n) => AllocId((1 << 63) | n), @@ -103,10 +103,10 @@ impl AllocId { self.0 >> 63 } /// Yields everything but the discriminant bits - fn index(self) -> u64 { + pub fn index(self) -> u64 { self.0 & ((1 << 63) - 1) } - fn into_alloc_id_kind(self) -> AllocIdKind { + pub fn into_alloc_id_kind(self) -> AllocIdKind { match self.discriminant() { 0 => AllocIdKind::Function(self.index() as usize), 1 => AllocIdKind::Runtime(self.index()), @@ -1091,6 +1091,17 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> { let dest = dest.to_ptr()?; self.check_relocation_edges(src, size)?; + // first copy the relocations to a temporary buffer, because + // `get_bytes_mut` will clear the relocations, which is correct, + // since we don't want to keep any relocations at the target. + + let relocations: Vec<_> = self.relocations(src, size)? + .map(|(&offset, &alloc_id)| { + // Update relocation offsets for the new positions in the destination allocation. + (offset + dest.offset - src.offset, alloc_id) + }) + .collect(); + let src_bytes = self.get_bytes_unchecked(src, size, align)?.as_ptr(); let dest_bytes = self.get_bytes_mut(dest, size, align)?.as_mut_ptr(); @@ -1116,7 +1127,8 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> { } self.copy_undef_mask(src, dest, size)?; - self.copy_relocations(src, dest, size)?; + // copy back the relocations + self.get_mut(dest.alloc_id)?.relocations.extend(relocations); Ok(()) } @@ -1330,22 +1342,6 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> { } Ok(()) } - - fn copy_relocations( - &mut self, - src: MemoryPointer, - dest: MemoryPointer, - size: u64, - ) -> EvalResult<'tcx> { - let relocations: Vec<_> = self.relocations(src, size)? - .map(|(&offset, &alloc_id)| { - // Update relocation offsets for the new positions in the destination allocation. - (offset + dest.offset - src.offset, alloc_id) - }) - .collect(); - self.get_mut(dest.alloc_id)?.relocations.extend(relocations); - Ok(()) - } } /// Undefined bytes diff --git a/src/librustc_mir/interpret/mod.rs b/src/librustc_mir/interpret/mod.rs index 634b8a0eeb8..9dcb1c9b0f5 100644 --- a/src/librustc_mir/interpret/mod.rs +++ b/src/librustc_mir/interpret/mod.rs @@ -27,7 +27,7 @@ pub use self::eval_context::{EvalContext, Frame, ResourceLimits, StackPopCleanup pub use self::lvalue::{Lvalue, LvalueExtra, GlobalId}; -pub use self::memory::{AllocId, Memory, MemoryPointer, MemoryKind, HasMemory, AccessKind}; +pub use self::memory::{AllocId, Memory, MemoryPointer, MemoryKind, HasMemory, AccessKind, AllocIdKind}; use self::memory::{PointerArithmetic, Lock}; diff --git a/tests/compile-fail/memleak_rc.rs b/tests/compile-fail/memleak_rc.rs index ee245daa310..b2bc6722afb 100644 --- a/tests/compile-fail/memleak_rc.rs +++ b/tests/compile-fail/memleak_rc.rs @@ -1,6 +1,3 @@ -// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation -// compile-flags: -Zmir-emit-validate=0 - //error-pattern: the evaluated program leaked memory use std::rc::Rc; diff --git a/tests/compile-fail/panic.rs b/tests/compile-fail/panic.rs index dbe80fecd00..4247cdaa463 100644 --- a/tests/compile-fail/panic.rs +++ b/tests/compile-fail/panic.rs @@ -1,6 +1,5 @@ -// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation +// FIXME: Probably failing due to https://github.com/solson/miri/issues/296 // compile-flags: -Zmir-emit-validate=0 - //error-pattern: the evaluated program panicked fn main() { diff --git a/tests/compile-fail/zst2.rs b/tests/compile-fail/zst2.rs index 0c46acb8ade..fa4ae9afdf6 100644 --- a/tests/compile-fail/zst2.rs +++ b/tests/compile-fail/zst2.rs @@ -1,6 +1,5 @@ -// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation +// FIXME: Probably failing due to https://github.com/solson/miri/issues/296 // compile-flags: -Zmir-emit-validate=0 - // error-pattern: the evaluated program panicked #[derive(Debug)] diff --git a/tests/compile-fail/zst3.rs b/tests/compile-fail/zst3.rs index a6d7fdd3552..320541552fb 100644 --- a/tests/compile-fail/zst3.rs +++ b/tests/compile-fail/zst3.rs @@ -1,6 +1,5 @@ -// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation +// FIXME: Probably failing due to https://github.com/solson/miri/issues/296 // compile-flags: -Zmir-emit-validate=0 - // error-pattern: the evaluated program panicked #[derive(Debug)] diff --git a/tests/run-pass/btreemap.rs b/tests/run-pass/btreemap.rs new file mode 100644 index 00000000000..55e6b07a658 --- /dev/null +++ b/tests/run-pass/btreemap.rs @@ -0,0 +1,17 @@ +// mir validation can't cope with `mem::uninitialized::<SomeEnum>()` +// compile-flags: -Zmir-emit-validate=0 + +#[derive(PartialEq, Eq, PartialOrd, Ord)] +pub enum Foo { + A(&'static str), + _B, + _C, +} + +pub fn main() { + let mut b = std::collections::BTreeSet::new(); + b.insert(Foo::A("\'")); + b.insert(Foo::A("/=")); + b.insert(Foo::A("#")); + b.insert(Foo::A("0o")); +} diff --git a/tests/run-pass/rc.rs b/tests/run-pass/rc.rs index ba1ef6d7043..c6de3675abe 100644 --- a/tests/run-pass/rc.rs +++ b/tests/run-pass/rc.rs @@ -1,6 +1,3 @@ -// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation -// compile-flags: -Zmir-emit-validate=0 - use std::cell::RefCell; use std::rc::Rc; diff --git a/tests/run-pass/send-is-not-static-par-for.rs b/tests/run-pass/send-is-not-static-par-for.rs index 19ff4b30db1..4ac1b5436f5 100644 --- a/tests/run-pass/send-is-not-static-par-for.rs +++ b/tests/run-pass/send-is-not-static-par-for.rs @@ -10,9 +10,6 @@ //ignore-windows -// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation -// compile-flags: -Zmir-emit-validate=0 - use std::sync::Mutex; fn par_for<I, F>(iter: I, f: F) diff --git a/tests/run-pass/std.rs b/tests/run-pass/std.rs index b15307bb48d..e0e23812d27 100644 --- a/tests/run-pass/std.rs +++ b/tests/run-pass/std.rs @@ -1,6 +1,3 @@ -// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation -// compile-flags: -Zmir-emit-validate=0 - use std::cell::{Cell, RefCell}; use std::rc::Rc; use std::sync::Arc; |
