LLVM ERROR: "Vector elements must have same size" with -Zmir-opt-level=3

fcd6b41
Opened by Matthias Krüger at 2022-11-06 10:15:38
<!-- Thank you for finding an Internal Compiler Error! 🧊 If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/ -->

Code

You may need a debug build of llvm to reproduce this. Interestingly this only triggers with mir-opt-level 3 but not with 2.

#[derive(Clone)]
pub struct Foo(Bar, u32);

#[derive(Clone, Copy)]
pub struct Bar(u8, u8, u8);

fn main() {
    let foo: Vec<Foo> = Vec::new();
    let _ = foo.clone();
}

Meta

<!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. -->

rustc --version --verbose:

rustc @ 371100b1fb811e604f7451eff3b06960587fe1af with full rustc + llvm debug assertions

Error output

rustc -Copt-level=3 103380.rs

rustc: /home/matthias/vcs/github/rust_debug_assertions/src/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:2907: llvm::Value *llvm::InnerLoopVectorizer::createBitOrPointerCast(llvm::Value *, llvm::VectorType *, const llvm::DataLayout &): Assertion `(DL.getTypeSizeInBits(SrcElemTy) == DL.getTypeSizeInBits(DstElemTy)) && "Vector elements must have same size"' failed.
<!-- Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your environment. E.g. `RUST_BACKTRACE=1 cargo build`. --> <details><summary><strong>Backtrace</strong></summary> <p>
rustc: /home/matthias/vcs/github/rust_debug_assertions/src/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:2907: llvm::Value *llvm::InnerLoopVectorizer::createBitOrPointerCast(llvm::Value *, llvm::VectorType *, const llvm::DataLayout &): Assertion `(DL.getTypeSizeInBits(SrcElemTy) == DL.getTypeSizeInBits(DstElemTy)) && "Vector elements must have same size"' failed.
</p> </details>
  1. <!-- Thank you for finding an Internal Compiler Error! 🧊 If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/ -->

    Code

    You may need a debug-assertions build of llvm to reproduce this. Interestingly this only triggers with mir-opt-level 3 but not with 2.

    #[derive(Clone)]
    pub struct Foo(Bar, u32);
    
    #[derive(Clone, Copy)]
    pub struct Bar(u8, u8, u8);
    
    fn main() {
        let foo: Vec<Foo> = Vec::new();
        let _ = foo.clone();
    }
    

    Meta

    <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. -->

    rustc --version --verbose:

    rustc @ 371100b1fb811e604f7451eff3b06960587fe1af with full rustc + llvm debug assertions
    

    Error output

    rustc -Copt-level=3 103380.rs

    rustc: /home/matthias/vcs/github/rust_debug_assertions/src/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:2907: llvm::Value *llvm::InnerLoopVectorizer::createBitOrPointerCast(llvm::Value *, llvm::VectorType *, const llvm::DataLayout &): Assertion `(DL.getTypeSizeInBits(SrcElemTy) == DL.getTypeSizeInBits(DstElemTy)) && "Vector elements must have same size"' failed.
    
    <!-- Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your environment. E.g. `RUST_BACKTRACE=1 cargo build`. --> <details><summary><strong>Backtrace</strong></summary> <p>
    rustc: /home/matthias/vcs/github/rust_debug_assertions/src/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:2907: llvm::Value *llvm::InnerLoopVectorizer::createBitOrPointerCast(llvm::Value *, llvm::VectorType *, const llvm::DataLayout &): Assertion `(DL.getTypeSizeInBits(SrcElemTy) == DL.getTypeSizeInBits(DstElemTy)) && "Vector elements must have same size"' failed.
    
    </p> </details>

    Matthias Krüger at 2022-11-06 01:55:58

  2. This is likely the same issue as https://github.com/llvm/llvm-project/issues/58722.

    Nikita Popov at 2022-11-06 10:12:46

  3. Probably :) , I looked for the assertion message in the rustc issue tracker but couldn't find anything related :sweat_smile:

    Matthias Krüger at 2022-11-06 10:15:38