Skip to content

Commit dd5b010

Browse files
committed
Merge remote-tracking branch 'origin/master' into memory
2 parents 2f0dcfb + 44a360d commit dd5b010

File tree

11 files changed

+41
-46
lines changed

11 files changed

+41
-46
lines changed

miri/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
// From rustc.
77
#[macro_use]
88
extern crate log;
9-
extern crate log_settings;
109
#[macro_use]
1110
extern crate rustc;
12-
extern crate rustc_const_math;
13-
extern crate rustc_data_structures;
1411
extern crate syntax;
1512

1613
use rustc::ty::{self, TyCtxt};
@@ -146,9 +143,9 @@ pub fn eval_main<'a, 'tcx: 'a>(
146143
}
147144
}
148145

149-
struct Evaluator;
146+
pub struct Evaluator;
150147
#[derive(Default)]
151-
struct EvaluatorData {
148+
pub struct EvaluatorData {
152149
/// Environment variables set by `setenv`
153150
/// Miri does not expose env vars from the host to the emulated program
154151
pub(crate) env_vars: HashMap<Vec<u8>, MemoryPointer>,
@@ -163,7 +160,7 @@ pub struct TlsEntry<'tcx> {
163160
}
164161

165162
#[derive(Default)]
166-
struct MemoryData<'tcx> {
163+
pub struct MemoryData<'tcx> {
167164
/// The Key to use for the next thread-local allocation.
168165
next_thread_local: TlsKey,
169166

src/librustc_mir/interpret/memory.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl LockInfo {
7979
pub struct AllocId(u64);
8080

8181
#[derive(Debug)]
82-
enum AllocIdKind {
82+
pub enum AllocIdKind {
8383
/// We can't ever have more than `usize::max_value` functions at the same time
8484
/// since we never "deallocate" functions
8585
Function(usize),
@@ -89,7 +89,7 @@ enum AllocIdKind {
8989
}
9090

9191
impl AllocIdKind {
92-
fn into_alloc_id(self) -> AllocId {
92+
pub fn into_alloc_id(self) -> AllocId {
9393
match self {
9494
AllocIdKind::Function(n) => AllocId(n as u64),
9595
AllocIdKind::Runtime(n) => AllocId((1 << 63) | n),
@@ -103,10 +103,10 @@ impl AllocId {
103103
self.0 >> 63
104104
}
105105
/// Yields everything but the discriminant bits
106-
fn index(self) -> u64 {
106+
pub fn index(self) -> u64 {
107107
self.0 & ((1 << 63) - 1)
108108
}
109-
fn into_alloc_id_kind(self) -> AllocIdKind {
109+
pub fn into_alloc_id_kind(self) -> AllocIdKind {
110110
match self.discriminant() {
111111
0 => AllocIdKind::Function(self.index() as usize),
112112
1 => AllocIdKind::Runtime(self.index()),
@@ -1091,6 +1091,17 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
10911091
let dest = dest.to_ptr()?;
10921092
self.check_relocation_edges(src, size)?;
10931093

1094+
// first copy the relocations to a temporary buffer, because
1095+
// `get_bytes_mut` will clear the relocations, which is correct,
1096+
// since we don't want to keep any relocations at the target.
1097+
1098+
let relocations: Vec<_> = self.relocations(src, size)?
1099+
.map(|(&offset, &alloc_id)| {
1100+
// Update relocation offsets for the new positions in the destination allocation.
1101+
(offset + dest.offset - src.offset, alloc_id)
1102+
})
1103+
.collect();
1104+
10941105
let src_bytes = self.get_bytes_unchecked(src, size, align)?.as_ptr();
10951106
let dest_bytes = self.get_bytes_mut(dest, size, align)?.as_mut_ptr();
10961107

@@ -1116,7 +1127,8 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
11161127
}
11171128

11181129
self.copy_undef_mask(src, dest, size)?;
1119-
self.copy_relocations(src, dest, size)?;
1130+
// copy back the relocations
1131+
self.get_mut(dest.alloc_id)?.relocations.extend(relocations);
11201132

11211133
Ok(())
11221134
}
@@ -1330,22 +1342,6 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
13301342
}
13311343
Ok(())
13321344
}
1333-
1334-
fn copy_relocations(
1335-
&mut self,
1336-
src: MemoryPointer,
1337-
dest: MemoryPointer,
1338-
size: u64,
1339-
) -> EvalResult<'tcx> {
1340-
let relocations: Vec<_> = self.relocations(src, size)?
1341-
.map(|(&offset, &alloc_id)| {
1342-
// Update relocation offsets for the new positions in the destination allocation.
1343-
(offset + dest.offset - src.offset, alloc_id)
1344-
})
1345-
.collect();
1346-
self.get_mut(dest.alloc_id)?.relocations.extend(relocations);
1347-
Ok(())
1348-
}
13491345
}
13501346

13511347
/// Undefined bytes

src/librustc_mir/interpret/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub use self::eval_context::{EvalContext, Frame, ResourceLimits, StackPopCleanup
2727

2828
pub use self::lvalue::{Lvalue, LvalueExtra, GlobalId};
2929

30-
pub use self::memory::{AllocId, Memory, MemoryPointer, MemoryKind, HasMemory, AccessKind};
30+
pub use self::memory::{AllocId, Memory, MemoryPointer, MemoryKind, HasMemory, AccessKind, AllocIdKind};
3131

3232
use self::memory::{PointerArithmetic, Lock};
3333

tests/compile-fail/memleak_rc.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation
2-
// compile-flags: -Zmir-emit-validate=0
3-
41
//error-pattern: the evaluated program leaked memory
52

63
use std::rc::Rc;

tests/compile-fail/panic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation
1+
// FIXME: Probably failing due to https://github.com/solson/miri/issues/296
22
// compile-flags: -Zmir-emit-validate=0
3-
43
//error-pattern: the evaluated program panicked
54

65
fn main() {

tests/compile-fail/zst2.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation
1+
// FIXME: Probably failing due to https://github.com/solson/miri/issues/296
22
// compile-flags: -Zmir-emit-validate=0
3-
43
// error-pattern: the evaluated program panicked
54

65
#[derive(Debug)]

tests/compile-fail/zst3.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation
1+
// FIXME: Probably failing due to https://github.com/solson/miri/issues/296
22
// compile-flags: -Zmir-emit-validate=0
3-
43
// error-pattern: the evaluated program panicked
54

65
#[derive(Debug)]

tests/run-pass/btreemap.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// mir validation can't cope with `mem::uninitialized::<SomeEnum>()`
2+
// compile-flags: -Zmir-emit-validate=0
3+
4+
#[derive(PartialEq, Eq, PartialOrd, Ord)]
5+
pub enum Foo {
6+
A(&'static str),
7+
_B,
8+
_C,
9+
}
10+
11+
pub fn main() {
12+
let mut b = std::collections::BTreeSet::new();
13+
b.insert(Foo::A("\'"));
14+
b.insert(Foo::A("/="));
15+
b.insert(Foo::A("#"));
16+
b.insert(Foo::A("0o"));
17+
}

tests/run-pass/rc.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation
2-
// compile-flags: -Zmir-emit-validate=0
3-
41
use std::cell::RefCell;
52
use std::rc::Rc;
63

tests/run-pass/send-is-not-static-par-for.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
//ignore-windows
1212

13-
// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation
14-
// compile-flags: -Zmir-emit-validate=0
15-
1613
use std::sync::Mutex;
1714

1815
fn par_for<I, F>(iter: I, f: F)

tests/run-pass/std.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation
2-
// compile-flags: -Zmir-emit-validate=0
3-
41
use std::cell::{Cell, RefCell};
52
use std::rc::Rc;
63
use std::sync::Arc;

0 commit comments

Comments
 (0)