Skip to content
Permalink
Browse files

Outright ignore any alignment in `const_field`

  • Loading branch information...
oli-obk committed Jun 13, 2019
1 parent 667f94c commit 921f0d9ca919245dfce2e0e672601619e7b0bf58
Showing with 4 additions and 8 deletions.
  1. +2 −4 src/librustc_mir/const_eval.rs
  2. +2 −4 src/librustc_mir/interpret/operand.rs
@@ -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,
@@ -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();
}
}
}

0 comments on commit 921f0d9

Please sign in to comment.
You can’t perform that action at this time.