Skip to content

line coverage shows coverage of comments #45102

@zmodem

Description

@zmodem
Bugzilla Link 45757
Resolution FIXED
Resolved on Aug 19, 2020 13:23
Version trunk
OS Linux
CC @zygoloid,@vedantk,@WesleyRosenblum,@yurybura,@ZequanWu

Extended Description

For example:

$ cat /tmp/a.c
int f(int x) {
if (x == 42) {
// Comment 1.
return 1;
}
// Comment 2.
return 0;
}

int main() {
f(1);
return 0;
}
$ bin/clang -fcoverage-mapping -fprofile-instr-generate /tmp/a.c
$ ./a.out
$ bin/llvm-profdata merge default.profraw -o default.profdata
$ bin/llvm-cov show a.out -instr-profile=default.profdata
1| 1|int f(int x) {
2| 1| if (x == 42) {
3| 0| // Comment 1.
4| 0| return 1;
5| 0| }
6| 1| // Comment 2.
7| 1| return 0;
8| 1|}
9| |
10| 1|int main() {
11| 1| f(1);
12| 1| return 0;
13| 1|}

Comment 1 gets an execution count of 0 (and shows on red background in the console) but Comment 2 is marked executed.

Does it make sense to have counters for comments, since they can't really be executed?

(This was reported by Chromium's code coverage folks in https://bugs.chromium.org/p/chromium/issues/detail?id=1074518)

It seems gcc/gcov doesn't count the comment lines (gcc -fprofile-arcs -ftest-coverage /tmp/a.c && ./a.out && gcov a.c && cat a.c.gcov).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclangClang issues not falling into any other category

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions