Skip to content

Commit 18f6a69

Browse files
compiler: Fix handling of repr(align(N), simd)
The attributes may not be sensible to combine in user code, but they should still work.
1 parent e2dc1a1 commit 18f6a69

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Diff for: compiler/rustc_ty_utils/src/layout.rs

+4
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,10 @@ fn layout_of_uncached<'tcx>(
517517
pref: dl.vector_align(size).pref,
518518
},
519519
)
520+
} else if let Some(align) = def.repr().align {
521+
let natural_align = dl.vector_align(size);
522+
let align = natural_align.max(AbiAndPrefAlign::new(align));
523+
(Abi::Vector { element: e_abi, count: e_len }, align)
520524
} else {
521525
(Abi::Vector { element: e_abi, count: e_len }, dl.vector_align(size))
522526
};

Diff for: tests/ui/simd/repr-align-and-simd.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

0 commit comments

Comments
 (0)