Skip to content

Functions sometimes disappear from coverage under MIR opts +Inline,+ConstProp #117012

Closed
@Zalathar

Description

@Zalathar

(Note that this is almost certainly a bug in coverage, not in MIR opts.)

Consider this coverage report, produced by x test run-coverage --bless on a new test file:

   LL|       |#![feature(coverage_attribute)]
   LL|       |// compile-flags: --edition=2021 -Copt-level=0 -Zmir-opt-level=1 -Zmir-enable-passes=+Inline,+ConstProp
   LL|       |
   LL|      8|#[derive(Debug, PartialEq, Eq)]
   LL|       |struct Foo(u32);
   LL|       |
   LL|      1|fn eq_good() {
   LL|      1|    assert_eq!(Foo(1), Foo(1));
   LL|      1|}
   LL|       |
   LL|      1|fn eq_good_message() {
   LL|      1|    assert_eq!(Foo(1), Foo(1), "message");
                                             ^0
   LL|      1|}
   LL|       |
   LL|       |fn ne_good() {
   LL|       |    assert_ne!(Foo(1), Foo(3));
   LL|       |}
   LL|       |
   LL|       |fn ne_good_message() {
   LL|       |    assert_ne!(Foo(1), Foo(3), "message");
   LL|       |}
   LL|       |
   LL|      1|fn eq_bad() {
   LL|      1|    assert_eq!(Foo(1), Foo(3));
   LL|      0|}
   LL|       |
   LL|       |fn eq_bad_message() {
   LL|       |    assert_eq!(Foo(1), Foo(3), "message");
   LL|       |}
   LL|       |
   LL|      1|fn ne_bad() {
   LL|      1|    assert_ne!(Foo(1), Foo(1));
   LL|      0|}
   LL|       |
   LL|      1|fn ne_bad_message() {
   LL|      1|    assert_ne!(Foo(1), Foo(1), "message");
   LL|      0|}
   LL|       |
   LL|       |#[coverage(off)]
   LL|       |fn main() {
   LL|       |    eq_good();
   LL|       |    eq_good_message();
   LL|       |    ne_good();
   LL|       |    ne_good_message();
   LL|       |
   LL|       |    let _ = std::panic::catch_unwind(eq_bad);
   LL|       |    let _ = std::panic::catch_unwind(eq_bad_message);
   LL|       |    let _ = std::panic::catch_unwind(ne_bad);
   LL|       |    let _ = std::panic::catch_unwind(ne_bad_message);
   LL|       |}

All of these functions should look roughly the same in the coverage report, but instead three of them (ne_good, ne_good_message, eq_bad_message) are completely missing, despite the fact that they are all executed.

The problem also occurs under -Copt-level=2 or -Zmir-opt-level=3, but I narrowed it down to just -Zmir-opt-level=1 plus the Inline and ConstProp passes. If I reduce the MIR opt level to 0, or remove either of those passes, I get the expected output where all functions are reported correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions