StorageLive: refresh storage (instead of UB) when local is already live

This commit is contained in:
Ralf Jung 2024-06-08 12:04:38 +02:00
parent d8fde50745
commit 9b05e154f3
3 changed files with 10 additions and 11 deletions

View file

@ -1103,11 +1103,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
Operand::Immediate(Immediate::Uninit)
});
// StorageLive expects the local to be dead, and marks it live.
// If the local is already live, deallocate its old memory.
let old = mem::replace(&mut self.frame_mut().locals[local].value, local_val);
if !matches!(old, LocalValue::Dead) {
throw_ub_custom!(fluent::const_eval_double_storage_live);
}
self.deallocate_local(old)?;
Ok(())
}
@ -1121,7 +1119,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
assert!(local != mir::RETURN_PLACE, "Cannot make return place dead");
trace!("{:?} is now dead", local);
// It is entirely okay for this local to be already dead (at least that's how we currently generate MIR)
// If the local is already dead, this is a NOP.
let old = mem::replace(&mut self.frame_mut().locals[local].value, LocalValue::Dead);
self.deallocate_local(old)?;
Ok(())