Skip to content

Miscompilation with LLVM 10 and 11 with codegen-units=1 #90153

Closed
@ehuss

Description

As part of the bootstrap bump in #90042, we are running into an issue where the x86_64-gnu-llvm-10 CI test is failing due to some miscompilation of some code.

The bump in the bootstrap brings in a change in cargo where tests now inherit profile settings from the dev/release profiles. The standard library tests are now being built with codegen-units=1 due to this. This has unearthed a miscompilation with llvm-10. In my tests, llvm-11 also seems to have the same problem, but llvm-12 seems to work correctly.

The test that seems to be failing is test_copy_within. Somehow the optimizations are causing it to compile down to an unconditional call to the first assert_eq being a failure.

This can be reproduced on latest master with llvm-10-dev installed on Ubuntu 20:

# llvm-10 is installed with `apt install llvm-10-dev`
# Also fails with llvm-11, but not llvm-12
./configure --llvm-root=/usr/lib/llvm-10 --enable-llvm-link-shared
./x.py build library/std

cat <<EOF >> foo.rs
fn main() {
    let mut bytes = *b"Hello, World!";
    bytes.copy_within(..3, 10);
    assert_eq!(&bytes, b"Hello, WorHel");
}
EOF

./build/x86_64-unknown-linux-gnu/stage1/bin/rustc foo.rs -Copt-level=3 -Ccodegen-units=1
./foo

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions