@@ -25,15 +25,22 @@ fn codegen_field<'tcx>(
2525 }
2626 match field_layout. ty . kind ( ) {
2727 ty:: Slice ( ..) | ty:: Str => simple ( fx) ,
28- ty:: Adt ( def, _) if def. repr ( ) . packed ( ) => {
29- assert_eq ! ( layout. align. abi. bytes( ) , 1 ) ;
30- simple ( fx)
31- }
3228 _ => {
33- // We have to align the offset for DST's
3429 let unaligned_offset = field_offset. bytes ( ) ;
35- let ( _, unsized_align) = crate :: unsize:: size_and_align_of ( fx, field_layout, extra) ;
3630
31+ // Get the alignment of the field
32+ let ( _, mut unsized_align) = crate :: unsize:: size_and_align_of ( fx, field_layout, extra) ;
33+
34+ // For packed types, we need to cap alignment.
35+ if let ty:: Adt ( def, _) = layout. ty . kind ( ) {
36+ if let Some ( packed) = def. repr ( ) . pack {
37+ let packed = fx. bcx . ins ( ) . iconst ( fx. pointer_type , packed. bytes ( ) as i64 ) ;
38+ let cmp = fx. bcx . ins ( ) . icmp ( IntCC :: UnsignedLessThan , unsized_align, packed) ;
39+ unsized_align = fx. bcx . ins ( ) . select ( cmp, unsized_align, packed) ;
40+ }
41+ }
42+
43+ // Bump the unaligned offset up to the appropriate alignment
3744 let one = fx. bcx . ins ( ) . iconst ( fx. pointer_type , 1 ) ;
3845 let align_sub_1 = fx. bcx . ins ( ) . isub ( unsized_align, one) ;
3946 let and_lhs = fx. bcx . ins ( ) . iadd_imm ( align_sub_1, unaligned_offset as i64 ) ;
0 commit comments