Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
xd009642 opened this issue Jul 30, 2021 · 4 comments
Labels
C-bug Category: This is a bug.

Comments

@xd009642
Copy link
Contributor

xd009642 commented Jul 30, 2021

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 (4927238 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

@xd009642 xd009642 added the C-bug Category: This is a bug. label Jul 30, 2021
@richkadel
Copy link
Contributor

richkadel commented Jul 31, 2021

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
Copy link
Contributor

Duplicate of #76038

@richkadel
Copy link
Contributor

Also see #76038 (comment)

@xd009642 xd009642 changed the title Test compiled with -Z instrument-coverage segfaults on windows Link-dead-code and -Z instrument-coverage causes segfault and no coverage on Windows Jul 31, 2021
@xd009642
Copy link
Contributor Author

Well as it's a duplicate I'll close this one then, thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants