about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm
diff options
context:
space:
mode:
authorHans Kratz <hans@appfour.com>2021-07-20 07:38:00 +0200
committerHans Kratz <hans@appfour.com>2021-08-04 23:36:13 +0200
commite89908231bede75f2e21959dfd851df85efd25c5 (patch)
tree6591dc6a88e7bfd7e04f2e80975ce83c9059b477 /compiler/rustc_codegen_llvm
parente4106581de25d31d94695372b299aa2c8b0bce8e (diff)
downloadrust-e89908231bede75f2e21959dfd851df85efd25c5.tar.gz
rust-e89908231bede75f2e21959dfd851df85efd25c5.zip
Don't cache projection if no padding is used.
In this case we can just return memory_index(index) which is readily available.
Diffstat (limited to 'compiler/rustc_codegen_llvm')
-rw-r--r--compiler/rustc_codegen_llvm/src/type_of.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs
index ad969658895..da292756673 100644
--- a/compiler/rustc_codegen_llvm/src/type_of.rs
+++ b/compiler/rustc_codegen_llvm/src/type_of.rs
@@ -99,6 +99,7 @@ fn struct_llfields<'a, 'tcx>(
     let mut prev_effective_align = layout.align.abi;
     let mut result: Vec<_> = Vec::with_capacity(1 + field_count * 2);
     let mut projection = vec![0; field_count];
+    let mut padding_used = false;
     for i in layout.fields.index_by_increasing_offset() {
         let target_offset = layout.fields.offset(i as usize);
         let field = layout.field(cx, i);
@@ -118,6 +119,7 @@ fn struct_llfields<'a, 'tcx>(
         assert!(target_offset >= offset);
         let padding = target_offset - offset;
         if padding != Size::ZERO {
+            padding_used = true;
             let padding_align = prev_effective_align.min(effective_field_align);
             assert_eq!(offset.align_to(padding_align) + padding, target_offset);
             result.push(cx.type_padding_filler(padding, padding_align));
@@ -145,7 +147,9 @@ fn struct_llfields<'a, 'tcx>(
     } else {
         debug!("struct_llfields: offset: {:?} stride: {:?}", offset, layout.size);
     }
-    cx.field_projection_cache.borrow_mut().insert(layout, projection);
+    if padding_used {
+        cx.field_projection_cache.borrow_mut().insert(layout, projection);
+    }
 
     (result, packed)
 }
@@ -361,9 +365,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
 
             FieldsShape::Arbitrary { .. } => match cx.field_projection_cache.borrow().get(self) {
                 Some(projection) => projection[index] as u64,
-                None => {
-                    bug!("TyAndLayout::llvm_field_index({:?}): field projection not cached", self)
-                }
+                None => self.fields.memory_index(index) as u64,
             },
         }
     }