Skip to content

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

Closed

Description

@EFanZh

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

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 13, 2023
  2. changed the title [-]Missing coverage on expression `assert!(!...)` statement[/-] [+]Missing coverage on `assert!(!...)` statements[/+] on Dec 13, 2023
  3. matthiaskrgr commented on Dec 13, 2023

    @matthiaskrgr
    Member

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

  4. EFanZh commented on Dec 13, 2023

    @EFanZh
    ContributorAuthor

    @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.

  5. taiki-e commented on Dec 13, 2023

    @taiki-e
    Member

    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

  6. added
    A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)
    on Dec 13, 2023
  7. Noratrieb commented on Dec 15, 2023

    @Noratrieb
    Member
  8. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 15, 2023
  9. Zalathar commented on Dec 16, 2023

    @Zalathar
    Member

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

    It was probably fixed by #118198.

  10. Noratrieb commented on Dec 16, 2023

    @Noratrieb
    Member

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

  11. Zalathar commented on Dec 16, 2023

    @Zalathar
    Member

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

    PR filed: #119011

  12. added a commit that references this issue on Dec 16, 2023
  13. added a commit that references this issue on Dec 17, 2023
  14. ranger-ross commented on Aug 31, 2024

    @ranger-ross
    Member

    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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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