提交 98cda6cb 编写于 作者: O Oliver Schneider

freeze -> static

上级 fd3bbfde
......@@ -119,9 +119,9 @@ fn description(&self) -> &str {
EvalError::TypeNotPrimitive(_) =>
"expected primitive type, got nonprimitive",
EvalError::ReallocatedStaticMemory =>
"tried to reallocate frozen memory",
"tried to reallocate static memory",
EvalError::DeallocatedStaticMemory =>
"tried to deallocate frozen memory",
"tried to deallocate static memory",
EvalError::Layout(_) =>
"rustc layout computation failed",
EvalError::UnterminatedCString(_) =>
......
......@@ -314,7 +314,7 @@ pub(super) fn pop_stack_frame(&mut self) -> EvalResult<'tcx> {
match frame.return_to_block {
StackPopCleanup::MarkStatic(mutable) => if let Lvalue::Global(id) = frame.return_lvalue {
let global_value = self.globals.get_mut(&id)
.expect("global should have been cached (freeze/static)");
.expect("global should have been cached (static)");
match global_value.value {
Value::ByRef(ptr) => self.memory.mark_static(ptr.alloc_id, mutable)?,
Value::ByVal(val) => if let PrimVal::Ptr(ptr) = val {
......@@ -332,7 +332,7 @@ pub(super) fn pop_stack_frame(&mut self) -> EvalResult<'tcx> {
assert!(global_value.mutable);
global_value.mutable = mutable;
} else {
bug!("StackPopCleanup::Freeze on: {:?}", frame.return_lvalue);
bug!("StackPopCleanup::MarkStatic on: {:?}", frame.return_lvalue);
},
StackPopCleanup::Goto(target) => self.goto_block(target),
StackPopCleanup::None => {},
......@@ -343,10 +343,8 @@ pub(super) fn pop_stack_frame(&mut self) -> EvalResult<'tcx> {
trace!("deallocating local");
self.memory.dump_alloc(ptr.alloc_id);
match self.memory.deallocate(ptr) {
// Any frozen memory means that it belongs to a constant or something referenced
// by a constant. We could alternatively check whether the alloc_id is frozen
// before calling deallocate, but this is much simpler and is probably the
// rare case.
// We could alternatively check whether the alloc_id is static before calling
// deallocate, but this is much simpler and is probably the rare case.
Ok(()) | Err(EvalError::DeallocatedStaticMemory) => {},
other => return other,
}
......
......@@ -39,7 +39,7 @@ pub struct Allocation {
pub align: u64,
/// Whether the allocation may be modified.
/// Use the `mark_static` method of `Memory` to ensure that an error occurs, if the memory of this
/// allocation is modified in the future.
/// allocation is modified or deallocated in the future.
pub static_kind: StaticKind,
}
......@@ -626,7 +626,7 @@ fn get_bytes_mut(&mut self, ptr: Pointer, size: u64, align: u64) -> EvalResult<'
impl<'a, 'tcx> Memory<'a, 'tcx> {
/// mark an allocation as static, either mutable or not
pub fn mark_static(&mut self, alloc_id: AllocId, mutable: bool) -> EvalResult<'tcx> {
// do not use `self.get_mut(alloc_id)` here, because we might have already frozen a
// do not use `self.get_mut(alloc_id)` here, because we might have already marked a
// sub-element or have circular pointers (e.g. `Rc`-cycles)
let relocations = match self.alloc_map.get_mut(&alloc_id) {
Some(&mut Allocation { ref mut relocations, static_kind: ref mut kind @ StaticKind::NotStatic, .. }) => {
......@@ -636,7 +636,7 @@ pub fn mark_static(&mut self, alloc_id: AllocId, mutable: bool) -> EvalResult<'t
StaticKind::Immutable
};
// take out the relocations vector to free the borrow on self, so we can call
// freeze recursively
// mark recursively
mem::replace(relocations, Default::default())
},
None if alloc_id == NEVER_ALLOC_ID || alloc_id == ZST_ALLOC_ID => return Ok(()),
......
fn main() {
let x = &1; // the `&1` is promoted to a constant, but it used to be that only the pointer is frozen, not the pointee
let x = &1; // the `&1` is promoted to a constant, but it used to be that only the pointer is marked static, not the pointee
let y = unsafe { &mut *(x as *const i32 as *mut i32) };
*y = 42; //~ ERROR tried to modify constant memory
assert_eq!(*x, 42);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册