Skip to content

Codegen backends should validate their assumed encodings of e.g. rustc layouts. #105282

Open
@eddyb

Description

@eddyb

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. the vector_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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions