Skip to content

Commit 921f0d9

Browse files
committed
Outright ignore any alignment in const_field
1 parent 667f94c commit 921f0d9

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,9 @@ pub fn const_field<'tcx>(
483483
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env);
484484
// get the operand again
485485
let mut op = ecx.eval_const_to_op(value, None).unwrap();
486-
// adjust the alignment of `op` to the one of the allocation, since it may be a field of a
486+
// Ignore the alignment when accessing the field, since it may be a field of a
487487
// packed struct and thus end up causing an alignment error if we read from it.
488-
if let ConstValue::ByRef(_, alloc) = value.val {
489-
op.force_alignment(alloc.align);
490-
}
488+
op.force_unaligned_access();
491489
// downcast
492490
let down = match variant {
493491
None => op,

src/librustc_mir/interpret/operand.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,9 @@ impl<'tcx, Tag> OpTy<'tcx, Tag> {
185185
/// packedness. We could clone the allocation and adjust the alignment, but that seems wasteful,
186186
/// since the alignment is already encoded in the allocation. We know it is alright, because
187187
/// validation checked everything before the initial constant entered match checking.
188-
pub(crate) fn force_alignment(&mut self, align: Align) {
188+
pub(crate) fn force_unaligned_access(&mut self) {
189189
if let Operand::Indirect(mplace) = &mut self.op {
190-
if align < mplace.align {
191-
mplace.align = align;
192-
}
190+
mplace.align = Align::from_bytes(1).unwrap();
193191
}
194192
}
195193
}

0 commit comments

Comments
 (0)