<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/93843>93843</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [llvm-cov] Feature Request / RFC - Optionally Combine Coverage of Template Instantiations
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          willson556
      </td>
    </tr>
</table>

<pre>
    ## 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](https://github.com/taiki-e/cargo-llvm-cov/issues/43).

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,

```c++
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 https://github.com/llvm/llvm-project/compare/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)?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVk1v47AR_TX0ZWBDofx58CFxKjTA7rbYBL0aI2oksaFIlRzZ6_76gpTi2C5QoECQxBY5H2_eey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