Skip to content

Commit e899082

Browse files
committed
Don't cache projection if no padding is used.
In this case we can just return memory_index(index) which is readily available.
1 parent e410658 commit e899082

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

compiler/rustc_codegen_llvm/src/type_of.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ fn struct_llfields<'a, 'tcx>(
9999
let mut prev_effective_align = layout.align.abi;
100100
let mut result: Vec<_> = Vec::with_capacity(1 + field_count * 2);
101101
let mut projection = vec![0; field_count];
102+
let mut padding_used = false;
102103
for i in layout.fields.index_by_increasing_offset() {
103104
let target_offset = layout.fields.offset(i as usize);
104105
let field = layout.field(cx, i);
@@ -118,6 +119,7 @@ fn struct_llfields<'a, 'tcx>(
118119
assert!(target_offset >= offset);
119120
let padding = target_offset - offset;
120121
if padding != Size::ZERO {
122+
padding_used = true;
121123
let padding_align = prev_effective_align.min(effective_field_align);
122124
assert_eq!(offset.align_to(padding_align) + padding, target_offset);
123125
result.push(cx.type_padding_filler(padding, padding_align));
@@ -145,7 +147,9 @@ fn struct_llfields<'a, 'tcx>(
145147
} else {
146148
debug!("struct_llfields: offset: {:?} stride: {:?}", offset, layout.size);
147149
}
148-
cx.field_projection_cache.borrow_mut().insert(layout, projection);
150+
if padding_used {
151+
cx.field_projection_cache.borrow_mut().insert(layout, projection);
152+
}
149153

150154
(result, packed)
151155
}
@@ -361,9 +365,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
361365

362366
FieldsShape::Arbitrary { .. } => match cx.field_projection_cache.borrow().get(self) {
363367
Some(projection) => projection[index] as u64,
364-
None => {
365-
bug!("TyAndLayout::llvm_field_index({:?}): field projection not cached", self)
366-
}
368+
None => self.fields.memory_index(index) as u64,
367369
},
368370
}
369371
}

0 commit comments

Comments
 (0)