Support allocation failures when interperting MIR
Note that this breaks Miri. Closes #79601
This commit is contained in:
@@ -48,7 +48,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
|
||||
);
|
||||
let layout = ecx.layout_of(body.return_ty().subst(tcx, cid.instance.substs))?;
|
||||
assert!(!layout.is_unsized());
|
||||
let ret = ecx.allocate(layout, MemoryKind::Stack);
|
||||
let ret = ecx.allocate(layout, MemoryKind::Stack)?;
|
||||
|
||||
let name =
|
||||
with_no_trimmed_paths(|| ty::tls::with(|tcx| tcx.def_path_str(cid.instance.def_id())));
|
||||
|
||||
@@ -306,7 +306,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
||||
Size::from_bytes(size as u64),
|
||||
align,
|
||||
interpret::MemoryKind::Machine(MemoryKind::Heap),
|
||||
);
|
||||
)?;
|
||||
ecx.write_scalar(Scalar::Ptr(ptr), dest)?;
|
||||
}
|
||||
_ => {
|
||||
|
||||
@@ -31,7 +31,11 @@ pub(crate) fn const_caller_location(
|
||||
trace!("const_caller_location: {}:{}:{}", file, line, col);
|
||||
let mut ecx = mk_eval_cx(tcx, DUMMY_SP, ty::ParamEnv::reveal_all(), false);
|
||||
|
||||
let loc_place = ecx.alloc_caller_location(file, line, col);
|
||||
// This can fail if rustc runs out of memory right here. Trying to emit an error would be
|
||||
// pointless, since that would require allocating more memory than a Location.
|
||||
let loc_place = ecx
|
||||
.alloc_caller_location(file, line, col)
|
||||
.expect("not enough memory to allocate location?");
|
||||
if intern_const_alloc_recursive(&mut ecx, InternKind::Constant, &loc_place).is_err() {
|
||||
bug!("intern_const_alloc_recursive should not error in this case")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user