@@ -999,7 +999,7 @@ where
999
999
}
1000
1000
1001
1001
_ => {
1002
- let mut data_variant = match this. variants {
1002
+ let ( mut data_variant, align ) = match this. variants {
1003
1003
// Within the discriminant field, only the niche itself is
1004
1004
// always initialized, so we only check for a pointer at its
1005
1005
// offset.
@@ -1012,13 +1012,24 @@ where
1012
1012
// using more niches than just null (e.g., the first page of
1013
1013
// the address space, or unaligned pointers).
1014
1014
Variants :: Multiple {
1015
- tag_encoding : TagEncoding :: Niche { untagged_variant, .. } ,
1015
+ tag_encoding :
1016
+ TagEncoding :: Niche { untagged_variant, ref niche_variants, .. } ,
1016
1017
tag_field,
1017
1018
..
1018
1019
} if this. fields . offset ( tag_field) == offset => {
1019
- Some ( this. for_variant ( cx, untagged_variant) )
1020
+ // When a non-zero niche exists, we cannot safely keep
1021
+ // the alignment of the pointer. These niches typically
1022
+ // don't meet the alignment requirements of the pointer.
1023
+ let align = if niche_variants. start ( ) . as_u32 ( ) != 0
1024
+ || niche_variants. end ( ) . as_u32 ( ) != 0
1025
+ {
1026
+ Some ( Align :: ONE )
1027
+ } else {
1028
+ None
1029
+ } ;
1030
+ ( Some ( this. for_variant ( cx, untagged_variant) ) , align)
1020
1031
}
1021
- _ => Some ( this) ,
1032
+ _ => ( Some ( this) , None ) ,
1022
1033
} ;
1023
1034
1024
1035
if let Some ( variant) = data_variant {
@@ -1055,10 +1066,10 @@ where
1055
1066
}
1056
1067
}
1057
1068
1058
- // Fixup info for the first field of a `Box`. Recursive traversal will have found
1059
- // the raw pointer, so size and align are set to the boxed type, but `pointee.safe`
1060
- // will still be `None`.
1061
1069
if let Some ( ref mut pointee) = result {
1070
+ // Fixup info for the first field of a `Box`. Recursive traversal will have found
1071
+ // the raw pointer, so size and align are set to the boxed type, but `pointee.safe`
1072
+ // will still be `None`.
1062
1073
if offset. bytes ( ) == 0
1063
1074
&& let Some ( boxed_ty) = this. ty . boxed_ty ( )
1064
1075
{
@@ -1069,6 +1080,9 @@ where
1069
1080
global : this. ty . is_box_global ( tcx) ,
1070
1081
} ) ;
1071
1082
}
1083
+ if let Some ( align) = align {
1084
+ pointee. align = align;
1085
+ }
1072
1086
}
1073
1087
1074
1088
result
0 commit comments