File tree 2 files changed +12
-4
lines changed
2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -1492,7 +1492,7 @@ impl<'a, 'tcx> LayoutDetails {
1492
1492
} ) . collect :: < Result < Vec < _ > , _ > > ( ) ?;
1493
1493
1494
1494
let offset = st[ i] . fields . offset ( field_index) + offset;
1495
- let LayoutDetails { size, mut align, .. } = st[ i] ;
1495
+ let LayoutDetails { mut size, mut align, .. } = st[ i] ;
1496
1496
1497
1497
let mut niche_align = niche. value . align ( dl) ;
1498
1498
let abi = if offset. bytes ( ) == 0 && niche. value . size ( dl) == size {
@@ -1504,6 +1504,7 @@ impl<'a, 'tcx> LayoutDetails {
1504
1504
Abi :: Aggregate { sized : true }
1505
1505
} ;
1506
1506
align = align. max ( niche_align) ;
1507
+ size = size. abi_align ( align) ;
1507
1508
1508
1509
return Ok ( tcx. intern_layout ( LayoutDetails {
1509
1510
variants : Variants :: NicheFilling {
Original file line number Diff line number Diff line change @@ -16,14 +16,21 @@ impl<T: Copy> Clone for Packed<T> {
16
16
fn clone ( & self ) -> Self { * self }
17
17
}
18
18
19
- fn main ( ) {
20
- let one = ( Some ( Packed ( ( & ( ) , 0 ) ) ) , true ) ;
19
+ fn sanity_check_size < T : Copy > ( one : T ) {
21
20
let two = [ one, one] ;
22
21
let stride = ( & two[ 1 ] as * const _ as usize ) - ( & two[ 0 ] as * const _ as usize ) ;
22
+ assert_eq ! ( stride, std:: mem:: size_of_val( & one) ) ;
23
+ }
23
24
25
+ fn main ( ) {
24
26
// This can fail if rustc and LLVM disagree on the size of a type.
25
27
// In this case, `Option<Packed<(&(), u32)>>` was erronously not
26
28
// marked as packed despite needing alignment `1` and containing
27
29
// its `&()` discriminant, which has alignment larger than `1`.
28
- assert_eq ! ( stride, std:: mem:: size_of_val( & one) ) ;
30
+ sanity_check_size ( ( Some ( Packed ( ( & ( ) , 0 ) ) ) , true ) ) ;
31
+
32
+ // In #46769, `Option<(Packed<&()>, bool)>` was found to have
33
+ // pointer alignment, without actually being aligned in size.
34
+ // E.g. on 64-bit platforms, it had alignment `8` but size `9`.
35
+ sanity_check_size ( Some ( ( Packed ( & ( ) ) , true ) ) ) ;
29
36
}
You can’t perform that action at this time.
0 commit comments