rust-lang / rust-lang/rust

Code coverage reports wrong count of loop header

Open
#151,554 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-code-coverage C-bug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

A simple test of the -C instrument-coverage feature returns the wrong count (9 instead of 10) of the loop header on line 4 when built with Rust 1.93.0:

main.rs:

fn main(){
    let mut sum: u32 = 0;

    for i in 1..10 {
        sum += i;
    }

    if false{
        println!("This code can't be reached");
    }
    println!("Sum: {}", sum);
}

Reproducer:

rustc -C instrument-coverage main.rs -o main
LLVM_PROFILE_FILE='testprof.profraw' ./main
llvm-profdata merge -sparse testprof.profraw -o testprof.profdata
llvm-cov show  main -instr-profile=testprof.profdata > coverage.out

This test works as expected with 1.92.0.

Meta
$ rustc +1.93.0 --version
rustc 1.93.0 (254b59607 2026-01-19)

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 with the main.rs reproducer and run the listed rustc, LLVM_PROFILE_FILE, llvm-profdata, and llvm-cov commands under Rust 1.93.0, then repeat with 1.92.0. Compare coverage.out, focusing on the loop header on line 4; done means the 1.93.0 report counts it as 10 rather than 9.

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
Active
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.