-cov LOC is inadequate for 1 liner branching; need a metric based on branching

Johan Engelen j at j.nl
Mon Feb 12 18:52:03 UTC 2018


On Monday, 5 February 2018 at 19:32:37 UTC, Timothee Cour wrote:
> just filed https://issues.dlang.org/show_bug.cgi?id=18377:

If I may add something semi-relevant to the current discussion, 
have a look here:
https://clang.llvm.org/docs/SourceBasedCodeCoverage.html

It is non-trivial to add llvm-cov support to LDC, but half the 
work is already done in LDC [*].
The current instrumentation implementation in Clang and LDC for 
PGO/coverage only instruments branch points, and is therefore 
faster than DMD's `-cov` (also present in LDC) but less precise: 
it assumes an exception-less execution flow. It's however quite 
easy to add precision and deal with exception-flow, at the cost 
of execution speed of course. It'll be interesting to investigate 
the cost/benefit! Let me know if you're interested in working on 
it.

A copy from Clang's documentation page, from which some cool 
ideas/capabilities can be glanced (needs monospaced font):
```
     1|   20|#define BAR(x) ((x) || (x))
                            ^20     ^2
     2|    2|template <typename T> void foo(T x) {
     3|   22|  for (unsigned I = 0; I < 10; ++I) { BAR(I); }
                                    ^22     ^20  ^20^20
     4|    2|}
------------------
| void foo<int>(int):
|      2|    1|template <typename T> void foo(T x) {
|      3|   11|  for (unsigned I = 0; I < 10; ++I) { BAR(I); }
|                                     ^11     ^10  ^10^10
|      4|    1|}
------------------
| void foo<float>(int):
|      2|    1|template <typename T> void foo(T x) {
|      3|   11|  for (unsigned I = 0; I < 10; ++I) { BAR(I); }
|                                     ^11     ^10  ^10^10
|      4|    1|}
------------------
```

cheers,
   Johan

[*] PGO instrumentation is the same, I can give some guidance to 
anybody who wants to work on it.


More information about the Digitalmars-d mailing list