Skip to content

Incorrect Rust region coverage? #324

@wintered

Description

@wintered

Hi,

cargo-llvm-cov reports that the following Rust code had 5 region coverage. Why? I count only 4: (1+2) both functions, (3) the if condition, (4) the "then branch". I also looked at the generated llvm-ir but could not figure out where the fifth region came from.

// main.rs
fn foo (c1: bool) {
    if c1 {
        println!("c1 true");
    }
    println!("join");
}

fn main() {
    foo(true);
}
Screenshot 2023-12-05 at 12 25 59 PM

The corresponding C++ program has 4 regions.

// main.cpp
#include <iostream>
void foo(bool c1) {
    if (c1) {
        std::cout << "c1 true" << std::endl;
    }
    std::cout << "join" << std::endl;
}
int main() {
    foo(true);
}
image

cargo-llvm-cov: 0.5.36
LLVM version 17.0.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-upstream-bugCategory: This is a bug of compiler or dependencies (the fix may require action in the upstream)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions