Skip to content

Possible solution to allow MIR inlining with -Zinstrument-coverage #83061

Closed
@richkadel

Description

@richkadel

Today, the MIR Inline pass is skipped if -Zinstrument-coverage is enabled.

I have an idea for a workaround that will allow MIR inlining.

I believe the problem is, when generating the LLVM coverage counters, and related coverage info used to generate the coverage map, each Coverage MIR statement assumes the coverage data should be associated with the current function being codegenned.

See

let coverageinfo = bx.tcx().coverageinfo(self.instance.def_id());

The self.instance is the function instance being generated. But if MIR inlining is performed, the original coverage counters for the inlined function will conflict with coverage counters of the current instance. For example, in both functions, the first counter is 1. But there will be two occurrences of that counter, for different functions in the original source. (That's essentially the problem.)

To fix this, I believe we can just add the original function's def_id to the MIR Coverage statement data.

Everywhere self.instance is used in the codegen_coverage() function should (probably) be replaced with an instance derived from the original def_id. This will apply those counters to the correct FunctionCoverage, and there will be no conflicts.

I may not be able to work on this very soon, and disabling MIR inlining is an OK workaround for now, but I wanted to capture the idea for me or someone else to try in the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)A-mir-opt-inliningArea: MIR inliningT-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