Auto merge of #2121 - RalfJung:less-ice, r=RalfJung

don't ICE when libcore is missing

Fixes https://github.com/rust-lang/miri/issues/2120
This commit is contained in:
bors 2022-05-15 08:27:43 +00:00
commit 8f7c8f7808
2 changed files with 16 additions and 8 deletions

View File

@ -172,15 +172,18 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
Evaluator::late_init(&mut ecx, config)?;
// Make sure we have MIR. We check MIR for some stable monomorphic function in libcore.
let sentinel = ecx.resolve_path(&["core", "ascii", "escape_default"]);
if !tcx.is_mir_available(sentinel.def.def_id()) {
tcx.sess.fatal("the current sysroot was built without `-Zalways-encode-mir`. Use `cargo miri setup` to prepare a sysroot that is suitable for Miri.");
let sentinel = ecx.try_resolve_path(&["core", "ascii", "escape_default"]);
if !matches!(sentinel, Some(s) if tcx.is_mir_available(s.def.def_id())) {
tcx.sess.fatal(
"the current sysroot was built without `-Zalways-encode-mir`, or libcore seems missing. \
Use `cargo miri setup` to prepare a sysroot that is suitable for Miri."
);
}
// Setup first stack-frame
// Setup first stack frame.
let entry_instance = ty::Instance::mono(tcx, entry_id);
// First argument is constructed later, because its skipped if the entry function uses #[start]
// First argument is constructed later, because it's skipped if the entry function uses #[start].
// Second argument (argc): length of `config.args`.
let argc = Scalar::from_machine_usize(u64::try_from(config.args.len()).unwrap(), &ecx);

View File

@ -71,11 +71,16 @@ fn try_resolve_did<'tcx>(tcx: TyCtxt<'tcx>, path: &[&str]) -> Option<DefId> {
}
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
/// Gets an instance for a path; fails gracefully if the path does not exist.
fn try_resolve_path(&self, path: &[&str]) -> Option<ty::Instance<'tcx>> {
let did = try_resolve_did(self.eval_context_ref().tcx.tcx, path)?;
Some(ty::Instance::mono(self.eval_context_ref().tcx.tcx, did))
}
/// Gets an instance for a path.
fn resolve_path(&self, path: &[&str]) -> ty::Instance<'tcx> {
let did = try_resolve_did(self.eval_context_ref().tcx.tcx, path)
.unwrap_or_else(|| panic!("failed to find required Rust item: {:?}", path));
ty::Instance::mono(self.eval_context_ref().tcx.tcx, did)
self.try_resolve_path(path)
.unwrap_or_else(|| panic!("failed to find required Rust item: {:?}", path))
}
/// Evaluates the scalar at the specified path. Returns Some(val)