rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.64k stars 12.63k forks source link

Link-dead-code and -Z instrument-coverage causes segfault and no coverage on Windows #87649

Closed xd009642 closed 3 years ago

xd009642 commented 3 years ago

With the following RUSTFLAGS=" -C link-dead-code -C debuginfo=2 --cfg=tarpaulin -Z instrument-coverage " and nightly-x86_64-pc-windows-msvc unchanged - rustc 1.56.0-nightly (492723897 2021-07-29) and this test:

//lib.rs
pub mod unused; 

pub fn branch_test_one(x: i32) -> i32 {
    if x > 5 {
        10
    } else {
        5
    }
}

#[cfg(test)]
mod tests {
    use branch_test_one;
    #[test]
    fn bad_test() {
        branch_test_one(2);
    }
}

unused.rs contains just a single function that's never used:

//unused.rs
pub fn hello() {
    println!("Hello world");
    println!("I'm never tested");
}

I expected to see to see it exit fine and the profraw file generated and the test exit successfully. Instead an empty profraw file is generated and the test segfaults. I don't know if this is connected to #77553 @richkadel

richkadel commented 3 years ago

This this is a known bug with link-dead-code implementation on msvc, not instrument-coverage. I implemented a different way to support dead code coverage (enabled by default) because I could never figure out why link-dead-code always caused the binary to segfault. The profraw file is empty because the binary segfaults before it has an opportunity to write the file on exit.

Can you do me a favor and retitle this issue to relate it to the link-dead-code option instead?

richkadel commented 3 years ago

Duplicate of #76038

richkadel commented 3 years ago

Also see https://github.com/rust-lang/rust/issues/76038#issuecomment-741920297

xd009642 commented 3 years ago

Well as it's a duplicate I'll close this one then, thanks :+1: