- // Look up llvm field index in projection cache if present. If no projection cache
- // is present no padding is used and the llvm field index matches the memory index.
- FieldsShape::Arbitrary { .. } => match cx.field_projection_cache.borrow().get(self) {
- Some(projection) => projection[index] as u64,
- None => self.fields.memory_index(index) as u64,
- },
+ FieldsShape::Arbitrary { .. } => {
+ let variant_index = match self.variants {
+ Variants::Single { index } => Some(index),
+ _ => None,
+ };
+
+ // Look up llvm field if indexes do not match memory order due to padding. If
+ // `field_remapping` is `None` no padding was used and the llvm field index
+ // matches the memory index.
+ match cx.type_lowering.borrow().get(&(self.ty, variant_index)) {
+ Some(TypeLowering { field_remapping: Some(ref prj), .. }) => prj[index] as u64,
+ Some(_) => self.fields.memory_index(index) as u64,
+ None => {
+ bug!("TyAndLayout::llvm_field_index({:?}): type info not found", self)
+ }
+ }
+ }