Skip to content

Missing coverage on assert!(!...) statements #118904

New issue

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

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

Already on GitHub? # to your account

Closed
EFanZh opened this issue Dec 13, 2023 · 8 comments
Closed

Missing coverage on assert!(!...) statements #118904

EFanZh opened this issue Dec 13, 2023 · 8 comments
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@EFanZh
Copy link
Contributor

EFanZh commented Dec 13, 2023

I tried this code:

fn main() {
    assert!(!false);
}

I expected to see this happen: Run this program with cargo-llvm-cov: cargo llvm-cov run --html, I expect the source code should be fully covered.

Instead, this happened: The assert! part in the source code is not covered. But if I change !false to true, the source will be fully covered, it seems that I can’t get assert! to be covered as long as the argument starts with an ! operator.

Meta

rustc --version --verbose:

rustc 1.76.0-nightly (f967532a4 2023-12-08)
binary: rustc
commit-hash: f967532a47eb728ada44473a5c4c2eca1a45fe30
commit-date: 2023-12-08
host: x86_64-pc-windows-msvc
release: 1.76.0-nightly
LLVM version: 17.0.5
@EFanZh EFanZh added the C-bug Category: This is a bug. label Dec 13, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 13, 2023
@EFanZh EFanZh changed the title Missing coverage on expression assert!(!...) statement Missing coverage on assert!(!...) statements Dec 13, 2023
@matthiaskrgr
Copy link
Member

Might be that llvm just optimizes it out as dead code. Do you see it with -Copt-level=0 ?

@EFanZh
Copy link
Contributor Author

EFanZh commented Dec 13, 2023

@matthiaskrgr: I think cargo-llvm-cov already uses opt-level=0 by default. Nevertheless, I have tested using env RUSTFLAGS='-Copt-level=0' cargo llvm-cov run --html, and the result is the same.

@taiki-e
Copy link
Member

taiki-e commented Dec 13, 2023

This may be a similar case to #110486. It seems that something odd is happening when the compiler gets the coverage of the code generated by the macro and maps it to the original code.

@rustbot label +A-code-coverage

@rustbot rustbot added the A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) label Dec 13, 2023
@Noratrieb
Copy link
Member

cc @Zalathar

@Noratrieb Noratrieb added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 15, 2023
@Zalathar
Copy link
Contributor

I can reproduce this with 2023-12-08 but not with 2023-12-14.

It was probably fixed by #118198.

@Noratrieb
Copy link
Member

Would it make sense to add a test for this specifically?

@Zalathar
Copy link
Contributor

Would it make sense to add a test for this specifically?

PR filed: #119011

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 16, 2023
coverage: Regression test for `assert!(!false)`

This verifies that rust-lang#118904 has already been fixed by rust-lang#118198.

---

`@rustbot` label +A-code-coverage
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 17, 2023
coverage: Regression test for `assert!(!false)`

This verifies that rust-lang#118904 has already been fixed by rust-lang#118198.

---

`@rustbot` label +A-code-coverage
@ranger-ross
Copy link
Contributor

ranger-ross commented Aug 31, 2024

A bit late, but I re-tested this on Rust 1.80.0 and it look like #119011 fixed the issue.

I think we are good to close this issue 👍

@EFanZh EFanZh closed this as completed Aug 31, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants