Skip to content

Commit

Permalink
actually we can reject all reads from mutable allocs in const-prop
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Mar 24, 2020
1 parent 7a73b87 commit 1939b4c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
}
// If the static allocation is mutable or if it has relocations (it may be legal to mutate
// the memory behind that in the future), then we can't const prop it.
// FIXME: we only check statics here (that have a `DefId`), not other mutable allocations.
// Why that?
if def_id.is_some()
&& (allocation.mutability == Mutability::Mut || allocation.relocations().len() > 0)
{
throw_machine_stop_str!("can't eval mutable statics in ConstProp");
if allocation.mutability == Mutability::Mut {
throw_machine_stop_str!("can't eval mutable globals in ConstProp");
}
if def_id.is_some() && allocation.relocations().len() > 0 {
throw_machine_stop_str!("can't eval statics with pointers in ConstProp");
}

Ok(())
Expand Down

0 comments on commit 1939b4c

Please sign in to comment.