Function rustc_codegen_llvm::coverageinfo::mapgen::add_unused_functions
source · fn add_unused_functions(cx: &CodegenCx<'_, '_>)
Expand description
When finalizing the coverage map, FunctionCoverage
only has the CodeRegion
s 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 -C 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
DefId
s (tcx
query mir_keys
) minus the codegenned DefId
s (codegenned_and_inlined_items
).
These unused functions don’t need to be codegenned, but we do need to add them to the function coverage map (in a single designated CGU) so that we still emit coverage mappings for them. We also end up adding their symbol names to a special global array that LLVM will include in its embedded coverage data.