Function rustc_codegen_llvm::coverageinfo::mapgen::add_unreachable_coverage [−][src]
fn add_unreachable_coverage<'tcx>(
tcx: TyCtxt<'tcx>,
function_coverage_map: &mut FxHashMap<Instance<'tcx>, FunctionCoverage<'tcx>>
)
When finalizing the coverage map, FunctionCoverage only has the CodeRegions and counters for
the functions that went through codegen; such as public functions and “used” functions
(functions referenced by other “used” or public items). Any other functions considered unused,
or “Unreachable” were still parsed and processed through the MIR stage.
We can find the unreachable functions by the set difference of all MIR DefIds (tcx query
mir_keys) minus the codegenned DefIds (tcx query collect_and_partition_mono_items).
HOWEVER the codegenned DefIds are partitioned across multiple CodegenUnits (CGUs), and
this function is processing a function_coverage_map for the functions (Instance/DefId)
allocated to only one of those CGUs. We must NOT inject any “Unreachable” functions’s
CodeRegions more than once, so we have to pick which CGU’s function_coverage_map to add
each “Unreachable” function to.
Some constraints:
- The file name of an “Unreachable” function must match the file name of the existing codegenned (covered) function to which the unreachable code regions will be added.
- The function to which the unreachable code regions will be added must not be a generic
function (must not have type parameters) because the coverage tools will get confused
if the codegenned function has more than one instantiation and additional
CodeRegions attached to only one of those instantiations.