preemptively change some assertions into errors

This commit is contained in:
Oliver Schneider 2016-10-21 11:51:24 +02:00
parent 2f81729e76
commit e82e6132ec
No known key found for this signature in database
GPG Key ID: 56D6EEA0FC67AC46

View File

@ -1224,9 +1224,12 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}
Lvalue::Global(cid) => {
let global_val = self.globals.get_mut(&cid).expect("global not cached");
assert!(global_val.mutable);
global_val.data = Some(Value::ByVal(val));
Ok(())
if global_val.mutable {
global_val.data = Some(Value::ByVal(val));
Ok(())
} else {
Err(EvalError::ModifiedConstantMemory)
}
}
}
}
@ -1240,7 +1243,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
match dest {
Lvalue::Global(cid) => {
let dest = *self.globals.get_mut(&cid).expect("global should be cached");
assert!(dest.mutable);
if !dest.mutable {
return Err(EvalError::ModifiedConstantMemory);
}
self.write_value_possibly_by_val(
src_val,
|this, val| *this.globals.get_mut(&cid).expect("already checked") = Global { data: Some(val), ..dest },