Skip to content

Commit

Permalink
Outright ignore any alignment in const_field
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jun 19, 2019
1 parent 667f94c commit 921f0d9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/librustc_mir/const_eval.rs
Expand Up @@ -483,11 +483,9 @@ pub fn const_field<'tcx>(
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env);
// get the operand again
let mut op = ecx.eval_const_to_op(value, None).unwrap();
// adjust the alignment of `op` to the one of the allocation, since it may be a field of a
// Ignore the alignment when accessing the field, since it may be a field of a
// packed struct and thus end up causing an alignment error if we read from it.
if let ConstValue::ByRef(_, alloc) = value.val {
op.force_alignment(alloc.align);
}
op.force_unaligned_access();
// downcast
let down = match variant {
None => op,
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_mir/interpret/operand.rs
Expand Up @@ -185,11 +185,9 @@ impl<'tcx, Tag> OpTy<'tcx, Tag> {
/// packedness. We could clone the allocation and adjust the alignment, but that seems wasteful,
/// since the alignment is already encoded in the allocation. We know it is alright, because
/// validation checked everything before the initial constant entered match checking.
pub(crate) fn force_alignment(&mut self, align: Align) {
pub(crate) fn force_unaligned_access(&mut self) {
if let Operand::Indirect(mplace) = &mut self.op {
if align < mplace.align {
mplace.align = align;
}
mplace.align = Align::from_bytes(1).unwrap();
}
}
}
Expand Down

0 comments on commit 921f0d9

Please sign in to comment.