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.
Today, the MIR
Inlinepass is skipped if-Zinstrument-coverageis 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
CoverageMIR statement assumes the coverage data should be associated with the current function being codegenned.See
rust/compiler/rustc_codegen_ssa/src/mir/coverageinfo.rs
Line 23 in 1973f84
The
self.instanceis 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 currentinstance. For example, in both functions, the first counter is1. 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_idto the MIRCoveragestatement data.Everywhere
self.instanceis used in thecodegen_coverage()function should (probably) be replaced with an instance derived from the originaldef_id. This will apply those counters to the correctFunctionCoverage, 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.