File tree 2 files changed +29
-2
lines changed
compiler/rustc_ty_utils/src
2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -506,6 +506,8 @@ fn layout_of_uncached<'tcx>(
506
506
. checked_mul ( e_len, dl)
507
507
. ok_or_else ( || error ( cx, LayoutError :: SizeOverflow ( ty) ) ) ?;
508
508
509
+ let requested_align = def. repr ( ) . align . clone ( ) ;
510
+
509
511
let ( abi, align) = if def. repr ( ) . packed ( ) && !e_len. is_power_of_two ( ) {
510
512
// Non-power-of-two vectors have padding up to the next power-of-two.
511
513
// If we're a packed repr, remove the padding while keeping the alignment as close
@@ -518,7 +520,13 @@ fn layout_of_uncached<'tcx>(
518
520
} ,
519
521
)
520
522
} else {
521
- ( Abi :: Vector { element : e_abi, count : e_len } , dl. vector_align ( size) )
523
+ let natural_align = dl. vector_align ( size) ;
524
+ let align = if let Some ( align) = requested_align {
525
+ natural_align. max ( AbiAndPrefAlign :: new ( align) )
526
+ } else {
527
+ natural_align
528
+ } ;
529
+ ( Abi :: Vector { element : e_abi, count : e_len } , align)
522
530
} ;
523
531
let size = size. align_to ( align. abi ) ;
524
532
@@ -536,7 +544,7 @@ fn layout_of_uncached<'tcx>(
536
544
largest_niche : e_ly. largest_niche ,
537
545
size,
538
546
align,
539
- max_repr_align : None ,
547
+ max_repr_align : requested_align ,
540
548
unadjusted_abi_align : align. abi ,
541
549
} )
542
550
}
Original file line number Diff line number Diff line change
1
+ //@ run-pass
2
+ // A regression test for https://github.com/rust-lang/rust/issues/130402
3
+ // Our SIMD representation did not combine correctly with the repr(align) attribute,
4
+ // and this will remain a concern regardless of what we do with SIMD types.
5
+ #![ feature( repr_simd) ]
6
+ use std:: mem:: { size_of, align_of} ;
7
+
8
+ #[ repr( simd, align( 64 ) ) ]
9
+ struct IntelsIdeaOfWhatAvx512Means ( [ u8 ; 32 ] ) ;
10
+
11
+ #[ repr( transparent) ]
12
+ struct DesignValidation ( IntelsIdeaOfWhatAvx512Means ) ;
13
+
14
+ fn main ( ) {
15
+ assert_eq ! ( 64 , size_of:: <IntelsIdeaOfWhatAvx512Means >( ) ) ;
16
+ assert_eq ! ( 64 , align_of:: <IntelsIdeaOfWhatAvx512Means >( ) ) ;
17
+ assert_eq ! ( 64 , size_of:: <DesignValidation >( ) ) ;
18
+ assert_eq ! ( 64 , align_of:: <DesignValidation >( ) ) ;
19
+ }
You can’t perform that action at this time.
0 commit comments