|
4 | 4 | use std::convert::TryInto;
|
5 | 5 |
|
6 | 6 | use rustc::{mir, ty};
|
7 |
| -use rustc::ty::layout::{self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerExt, VariantIdx}; |
| 7 | +use rustc::ty::layout::{ |
| 8 | + self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerExt, VariantIdx, Align, |
| 9 | +}; |
8 | 10 |
|
9 | 11 | use rustc::mir::interpret::{
|
10 | 12 | GlobalId, AllocId, CheckInAllocMsg,
|
@@ -177,6 +179,21 @@ impl<'tcx, Tag> From<ImmTy<'tcx, Tag>> for OpTy<'tcx, Tag> {
|
177 | 179 | }
|
178 | 180 | }
|
179 | 181 |
|
| 182 | +impl<'tcx, Tag> OpTy<'tcx, Tag> { |
| 183 | + /// This function exists solely for pattern matching. If we pattern match a packed struct with |
| 184 | + /// an ADT field, the constant representing that field will have lost the information about the |
| 185 | + /// packedness. We could clone the allocation and adjust the alignment, but that seems wasteful, |
| 186 | + /// since the alignment is already encoded in the allocation. We know it is alright, because |
| 187 | + /// validation checked everything before the initial constant entered match checking. |
| 188 | + pub(crate) fn force_alignment(&mut self, align: Align) { |
| 189 | + if let Operand::Indirect(mplace) = &mut self.op { |
| 190 | + if align < mplace.align { |
| 191 | + mplace.align = align; |
| 192 | + } |
| 193 | + } |
| 194 | + } |
| 195 | +} |
| 196 | + |
180 | 197 | impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag>
|
181 | 198 | {
|
182 | 199 | #[inline]
|
|
0 commit comments