rust-lang / rust-lang/rust

Optimization regression: array argument somehow produces null check?

Open
#139,415 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-ABI A-codegen A-LLVM C-optimization I-slow T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Minimal reproducer:

#[no_mangle]
pub fn f1(v: [&mut usize; 1]) {
    for x in v {
        *x += 1;
    }
}

Results in:

f1:
        test    rdi, rdi
        je      .LBB0_2
        inc     qword ptr [rdi]
.LBB0_2:
        ret

Rust's semantics don't allow v to ever be NULL! I don't know where the test rdi, rdi is coming from!

This regressed between 1.78 and 1.79.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the minimal Rust example and comparing its generated assembly on Rust 1.78 and 1.79 using the linked Rust Compiler Explorer case. Trace the regression through the compiler output to determine why the null check appears. Done means the unnecessary check is removed without changing the function's behavior or safety semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.