Open
Description
Specifically the thing that came to mind is that rustc_codegen_llvm
could assert LLVMSizeOf
matches the rustc
Layout
every time it builds a LLVM type from a layout.
(and this should hopefully be cheap enough that we could always have it enabled)
(I generally dislike debug asserts as they can't be relied upon to enforce soundness...)
The motivating example is a discussion around a #[repr(simd)] struct i32x3([i32; 3]);
type having size 12:
- non-power-of-2 Simd types have wrong size portable-simd#319 (comment)
- but as I note in the comment linked above, LLVM's
<3 x i32>
is 16 bytes, so that would be illegal- (16 bytes at least in "stride", which LLVM doesn't seem to name as such - it doesn't read/write 16 bytes on load/store, so it definitely seems to have more than once concept of "size" even for primitives)
- (and no,
#[repr(packed)]
doesn't seem to do anything today, in combination with#[repr(simd)]
, so you couldn't get the 12-byte layout without changing e.g. thevector_align
algorithm in the compiler)
I'm unsure about the GCC backend but presumably it should also be able to do this? (cc @antoyo)
cc @rust-lang/wg-llvm @bjorn3