Skip to content

[llvm-cov] Feature Request / RFC - Optionally Combine Coverage of Template Instantiations #93843

@willson556

Description

@willson556

Problem Description

Currently, when evaluating branch coverage metrics, each instantiation of a C++ templated function is counted as if it were separate source code. This seems to also apply to rust.

This is an issue because if you're trying to target high branch coverage for regulatory reasons, it can be impossible to do so for core infrastructure types. For example, if you have a class like,

template <class T, size_t N>
class Array;

each value of N will create different instantiations. In the tests directly targeting Array, we can take care to use only a few values of N and achieve full coverage of each.

However, other components in projects make use of Array, create new instantiations of it in their tests, and then contribute partial coverage of Array in their tests. This creates the counter-intuitive situation of adding tests reducing the coverage metrics.

Proposed Solution

Add a command line option to llvm-cov that merges the coverage from all instantiations rather than considering them separately.

I have a prototype of this at main...StaflSystems:llvm-project:feature/CoverageCombineInstantiations. I expect this would need substantial re-work to be upstream-able, not least because it's neglecting MC/DC coverage at the moment.

Based on the note at the top of https://software-dl.ti.com/codegen/docs/tiarmclang/rel3_2_0_LTS/compiler_manual/code_coverage/source_based_code_coverage.html, tiarmclang seems to have an alternative of this where the most-covered instantiation is used for metrics (but to my knowledge that is not open source).

Is this feature something that would be considered? If so, is there anyone that can give me some advice on how best to implement it (I have no prior knowledge of the LLVM codebase)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImproving things as opposed to bug fixing, e.g. new or missing featuretools:llvm-cov

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions