@@ -25,15 +25,22 @@ fn codegen_field<'tcx>(
25
25
}
26
26
match field_layout. ty . kind ( ) {
27
27
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
- }
32
28
_ => {
33
- // We have to align the offset for DST's
34
29
let unaligned_offset = field_offset. bytes ( ) ;
35
- let ( _, unsized_align) = crate :: unsize:: size_and_align_of ( fx, field_layout, extra) ;
36
30
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
37
44
let one = fx. bcx . ins ( ) . iconst ( fx. pointer_type , 1 ) ;
38
45
let align_sub_1 = fx. bcx . ins ( ) . isub ( unsized_align, one) ;
39
46
let and_lhs = fx. bcx . ins ( ) . iadd_imm ( align_sub_1, unaligned_offset as i64 ) ;
0 commit comments