fn add_unused_functions(cx: &CodegenCx<'_, '_>)
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 -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 DefIds (tcx query mir_keys) minus the codegenned DefIds (tcx query codegened_and_inlined_items).

These unused functions are then codegen’d in one of the CGUs which is marked as the “code coverage dead code cgu” during the partitioning process. This prevents us from generating code regions for the same function more than once which can lead to linker errors regarding duplicate symbols.