@@ -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