Skip to content

Code coverage reports wrong count of loop header #151554

@pmur

Description

@pmur

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)C-bugCategory: This is a bug.T-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