Skip to content

Commit e73d0a3

Browse files
authored
Merge branch 'master' into fixme
2 parents 36a2b89 + 21fd5fd commit e73d0a3

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

src/bin/cargo-miri.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ fn setup(ask_user: bool) {
155155
File::create(dir.join("Xargo.toml")).unwrap()
156156
.write_all(br#"
157157
[dependencies.std]
158+
default_features = false
159+
# We need the `panic_unwind` feature because we use the `unwind` panic strategy.
160+
# Using `abort` works for libstd, but then libtest will not compile.
158161
features = ["panic_unwind"]
159162
160163
[dependencies.test]

src/lib.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -310,26 +310,9 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
310310

311311
const STATIC_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::MutStatic);
312312

313+
#[inline(always)]
313314
fn enforce_validity(ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool {
314-
if !ecx.machine.validate {
315-
return false;
316-
}
317-
318-
// Some functions are whitelisted until we figure out how to fix them.
319-
// We walk up the stack a few frames to also cover their callees.
320-
const WHITELIST: &[(&str, &str)] = &[
321-
// Uses mem::uninitialized
322-
("std::sys::windows::mutex::Mutex::", ""),
323-
];
324-
for frame in ecx.stack().iter()
325-
.rev().take(3)
326-
{
327-
let name = frame.instance.to_string();
328-
if WHITELIST.iter().any(|(prefix, suffix)| name.starts_with(prefix) && name.ends_with(suffix)) {
329-
return false;
330-
}
331-
}
332-
true
315+
ecx.machine.validate
333316
}
334317

335318
/// Returns Ok() when the function was handled, fail otherwise

tests/compiletest.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,33 @@ fn is_target_dir<P: Into<PathBuf>>(path: P) -> bool {
124124
path.metadata().map(|m| m.is_dir()).unwrap_or(false)
125125
}
126126

127-
fn for_all_targets<F: FnMut(String)>(sysroot: &Path, mut f: F) {
127+
fn target_has_std<P: Into<PathBuf>>(path: P) -> bool {
128+
let mut path = path.into();
129+
path.push("lib");
130+
std::fs::read_dir(path)
131+
.expect("invalid target")
132+
.map(|entry| entry.unwrap())
133+
.filter(|entry| entry.file_type().unwrap().is_file())
134+
.filter_map(|entry| entry.file_name().into_string().ok())
135+
.any(|file_name| file_name.starts_with("libstd") && file_name.ends_with(".rlib"))
136+
}
137+
138+
139+
fn for_all_targets<F: FnMut(String)>(sysroot: &Path, f: F) {
128140
let target_dir = sysroot.join("lib").join("rustlib");
129-
for entry in std::fs::read_dir(target_dir).expect("invalid sysroot") {
130-
let entry = entry.unwrap();
131-
if !is_target_dir(entry.path()) {
132-
continue;
133-
}
134-
let target = entry.file_name().into_string().unwrap();
135-
f(target);
141+
let mut targets = std::fs::read_dir(target_dir)
142+
.expect("invalid sysroot")
143+
.map(|entry| entry.unwrap())
144+
.filter(|entry| is_target_dir(entry.path()))
145+
.filter(|entry| target_has_std(entry.path()))
146+
.map(|entry| entry.file_name().into_string().unwrap())
147+
.peekable();
148+
149+
if targets.peek().is_none() {
150+
panic!("No valid targets found");
136151
}
152+
153+
targets.for_each(f);
137154
}
138155

139156
fn get_sysroot() -> PathBuf {

0 commit comments

Comments
 (0)