diff --git a/src/bin/cargo-miri.rs b/src/bin/cargo-miri.rs index 4c83c5bd3dc..2dc6eee5de9 100644 --- a/src/bin/cargo-miri.rs +++ b/src/bin/cargo-miri.rs @@ -155,6 +155,9 @@ fn setup(ask_user: bool) { File::create(dir.join("Xargo.toml")).unwrap() .write_all(br#" [dependencies.std] +default_features = false +# We need the `panic_unwind` feature because we use the `unwind` panic strategy. +# Using `abort` works for libstd, but then libtest will not compile. features = ["panic_unwind"] [dependencies.test] diff --git a/src/lib.rs b/src/lib.rs index 9739a7a95b6..ec4e621a24a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -310,26 +310,9 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> { const STATIC_KIND: Option = Some(MiriMemoryKind::MutStatic); + #[inline(always)] fn enforce_validity(ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool { - if !ecx.machine.validate { - return false; - } - - // Some functions are whitelisted until we figure out how to fix them. - // We walk up the stack a few frames to also cover their callees. - const WHITELIST: &[(&str, &str)] = &[ - // Uses mem::uninitialized - ("std::sys::windows::mutex::Mutex::", ""), - ]; - for frame in ecx.stack().iter() - .rev().take(3) - { - let name = frame.instance.to_string(); - if WHITELIST.iter().any(|(prefix, suffix)| name.starts_with(prefix) && name.ends_with(suffix)) { - return false; - } - } - true + ecx.machine.validate } /// Returns Ok() when the function was handled, fail otherwise diff --git a/tests/compiletest.rs b/tests/compiletest.rs index de693bd4632..1c11d07c1bc 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -124,16 +124,33 @@ fn is_target_dir>(path: P) -> bool { path.metadata().map(|m| m.is_dir()).unwrap_or(false) } -fn for_all_targets(sysroot: &Path, mut f: F) { +fn target_has_std>(path: P) -> bool { + let mut path = path.into(); + path.push("lib"); + std::fs::read_dir(path) + .expect("invalid target") + .map(|entry| entry.unwrap()) + .filter(|entry| entry.file_type().unwrap().is_file()) + .filter_map(|entry| entry.file_name().into_string().ok()) + .any(|file_name| file_name.starts_with("libstd") && file_name.ends_with(".rlib")) +} + + +fn for_all_targets(sysroot: &Path, f: F) { let target_dir = sysroot.join("lib").join("rustlib"); - for entry in std::fs::read_dir(target_dir).expect("invalid sysroot") { - let entry = entry.unwrap(); - if !is_target_dir(entry.path()) { - continue; - } - let target = entry.file_name().into_string().unwrap(); - f(target); + let mut targets = std::fs::read_dir(target_dir) + .expect("invalid sysroot") + .map(|entry| entry.unwrap()) + .filter(|entry| is_target_dir(entry.path())) + .filter(|entry| target_has_std(entry.path())) + .map(|entry| entry.file_name().into_string().unwrap()) + .peekable(); + + if targets.peek().is_none() { + panic!("No valid targets found"); } + + targets.for_each(f); } fn get_sysroot() -> PathBuf {