@@ -99,6 +99,7 @@ fn struct_llfields<'a, 'tcx>(
99
99
let mut prev_effective_align = layout. align . abi ;
100
100
let mut result: Vec < _ > = Vec :: with_capacity ( 1 + field_count * 2 ) ;
101
101
let mut projection = vec ! [ 0 ; field_count] ;
102
+ let mut padding_used = false ;
102
103
for i in layout. fields . index_by_increasing_offset ( ) {
103
104
let target_offset = layout. fields . offset ( i as usize ) ;
104
105
let field = layout. field ( cx, i) ;
@@ -118,6 +119,7 @@ fn struct_llfields<'a, 'tcx>(
118
119
assert ! ( target_offset >= offset) ;
119
120
let padding = target_offset - offset;
120
121
if padding != Size :: ZERO {
122
+ padding_used = true ;
121
123
let padding_align = prev_effective_align. min ( effective_field_align) ;
122
124
assert_eq ! ( offset. align_to( padding_align) + padding, target_offset) ;
123
125
result. push ( cx. type_padding_filler ( padding, padding_align) ) ;
@@ -145,7 +147,9 @@ fn struct_llfields<'a, 'tcx>(
145
147
} else {
146
148
debug ! ( "struct_llfields: offset: {:?} stride: {:?}" , offset, layout. size) ;
147
149
}
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
+ }
149
153
150
154
( result, packed)
151
155
}
@@ -361,9 +365,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
361
365
362
366
FieldsShape :: Arbitrary { .. } => match cx. field_projection_cache . borrow ( ) . get ( self ) {
363
367
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 ,
367
369
} ,
368
370
}
369
371
}
0 commit comments