Skip to content

Commit

Permalink
Rollup merge of rust-lang#49216 - bjorn3:patch-1, r=estebank
Browse files Browse the repository at this point in the history
Don't check interpret_interner when accessing a static to fix miri mutable statics

Mutable statics don't work in my PR to fix the standalone [miri](https://github.com/solson/miri), as init_static didn't get called when the interpret_interner already contained a entry for the static, which is always immutable.

cc rust-lang/miri#364
  • Loading branch information
kennytm committed Mar 22, 2018
2 parents 70ae917 + 5aa29c4 commit 346a46e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
8 changes: 8 additions & 0 deletions src/librustc_mir/interpret/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ impl<'mir, 'tcx> super::Machine<'mir, 'tcx> for CompileTimeEvaluator {
ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
cid: GlobalId<'tcx>,
) -> EvalResult<'tcx, AllocId> {
let alloc = ecx
.tcx
.interpret_interner
.get_cached(cid.instance.def_id());
// Don't evaluate when already cached to prevent cycles
if let Some(alloc) = alloc {
return Ok(alloc)
}
// ensure the static is computed
ecx.const_eval(cid)?;
Ok(ecx
Expand Down
32 changes: 10 additions & 22 deletions src/librustc_mir/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,29 +197,17 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
},

Static(ref static_) => {
let alloc = self
.tcx
.interpret_interner
.get_cached(static_.def_id);
let layout = self.layout_of(self.place_ty(mir_place))?;
if let Some(alloc) = alloc {
Place::Ptr {
ptr: MemoryPointer::new(alloc, 0).into(),
align: layout.align,
extra: PlaceExtra::None,
}
} else {
let instance = ty::Instance::mono(*self.tcx, static_.def_id);
let cid = GlobalId {
instance,
promoted: None
};
let alloc = Machine::init_static(self, cid)?;
Place::Ptr {
ptr: MemoryPointer::new(alloc, 0).into(),
align: layout.align,
extra: PlaceExtra::None,
}
let instance = ty::Instance::mono(*self.tcx, static_.def_id);
let cid = GlobalId {
instance,
promoted: None
};
let alloc = Machine::init_static(self, cid)?;
Place::Ptr {
ptr: MemoryPointer::new(alloc, 0).into(),
align: layout.align,
extra: PlaceExtra::None,
}
}

Expand Down

0 comments on commit 346a46e

Please sign in to comment.