[cfe-dev] Remove code coverage counter for "empty" lines

Calixte Denizet via cfe-dev cfe-dev at lists.llvm.org
Mon Sep 24 12:34:32 PDT 2018


Hi,

When making code coverage, there are some counters on closing braces.
In some case it's due to "return void" with a debugloc corresponding to '}'
(see line 4) or due to cleanup stuff put at the end of a scope (see line
20, aaa's dtor is called).
Especially with c++, some "implicit" code (i.e. not written explicitly by
the user) could be added at the beginning of a scope and at the end.
Here are two example of outputs produced by clang and gcc.

With clang 7:
-:    1:struct A {
-:    2:
1:    3:    A() {}
-:    4:
-:    5:    ~A() {
1:    6:    }
-:    7:};
-:    8:
-:    9:void foo(int K) {
1:   10:}
-:   11:
-:   12:int main() {
1:   13:    A aaa;
1:   14:    int x = 1;
1:   15:    foo(x);
1:   16:    x = x + 2;
-:   17:
1:   18:    return x;
1:   19:}

With gcc 8:
-:    1:struct A {
-:    2:
1:    3:    A() {}
-:    4:
1:    5:    ~A() {
1:    6:    }
-:    7:};
-:    8:
1:    9:void foo(int K) {
1:   10:}
-:   11:
1:   12:int main() {
1:   13:    A aaa;
1:   14:    int x = 1;
1:   15:    foo(x);
1:   16:    x = x + 2;
-:   17:
1:   18:    return x;
-:   19:}

So I'd like to have coverage for lines which contain only "explicit" code
to have a clear information to give to different kinds of people (I spent
myself some time to understand why I had coverage on line like "} //
namespace foo").
So we could add an option in clang (no idea of the name right now) to allow
user to have coverage for explicit code.
And so have this output:
-:    1:struct A {
-:    2:
1:    3:    A() {}
-:    4:
1:    5:    ~A() {
-:    6:    }
-:    7:};
-:    8:
1:    9:void foo(int K) {
-:   10:}
-:   11:
1:   12:int main() {
1:   13:    A aaa;
1:   14:    int x = 1;
1:   15:    foo(x);
1:   16:    x = x + 2;
-:   17:
1:   18:    return x;
-:   19:}

Calixte
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180924/79cf186f/attachment.html>


More information about the cfe-dev mailing list