Skip to content

Commit dd7735b

Browse files
committed
make StorageLive kill the current value of the local
1 parent db6ce46 commit dd7735b

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/eval_context.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,15 +1720,12 @@ impl<'tcx> Frame<'tcx> {
17201720
return Ok(());
17211721
}
17221722

1723-
pub fn storage_live(&mut self, local: mir::Local) -> EvalResult<'tcx> {
1723+
pub fn storage_live(&mut self, local: mir::Local) -> EvalResult<'tcx, Option<Value>> {
17241724
trace!("{:?} is now live", local);
1725-
if self.locals[local.index() - 1].is_some() {
1726-
// The variables comes live now, but was already accessed previously, when it was still dead
1727-
return Err(EvalError::DeadLocal);
1728-
} else {
1729-
self.locals[local.index() - 1] = Some(Value::ByVal(PrimVal::Undef));
1730-
}
1731-
return Ok(());
1725+
1726+
let old = self.locals[local.index() - 1];
1727+
self.locals[local.index() - 1] = Some(Value::ByVal(PrimVal::Undef)); // StorageLive *always* kills the value that's currently stored
1728+
return Ok(old);
17321729
}
17331730

17341731
/// Returns the old value of the local

src/step.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,12 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
132132
Lvalue::Local{ frame, local, field: None } if self.stack.len() == frame+1 => (frame, local),
133133
_ => return Err(EvalError::Unimplemented("Stroage annotations must refer to locals of the topmost stack frame.".to_owned())) // FIXME maybe this should get its own error type
134134
};
135-
match stmt.kind {
135+
let old_val = match stmt.kind {
136136
StorageLive(_) => self.stack[frame].storage_live(local)?,
137-
_ => {
138-
let old_val = self.stack[frame].storage_dead(local)?;
139-
self.deallocate_local(old_val)?;
140-
}
137+
StorageDead(_) => self.stack[frame].storage_dead(local)?,
138+
_ => bug!("We already checked that we are a storage stmt")
141139
};
140+
self.deallocate_local(old_val)?;
142141
}
143142

144143
// Defined to do nothing. These are added by optimization passes, to avoid changing the

0 commit comments

Comments
 (0)