Function rustc_codegen_llvm::coverageinfo::mapgen::add_unused_functions [−][src]
fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>)Expand description
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, but were not
codegenned. (Note that -Clink-dead-code can force some unused code to be codegenned, but
that flag is known to cause other errors, when combined with -Z instrument-coverage; and
-Clink-dead-code will not generate code for unused generic functions.)
We can find the unused functions (including generic functions) by the set difference of all MIR
DefIds (tcx query mir_keys) minus the codegenned DefIds (tcx query
codegened_and_inlined_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 unused functions’s CodeRegions
more than once, so we have to pick a CGUs function_coverage_map into which the unused
function will be inserted.