[llvm-bugs] [Bug 45757] New: line coverage shows coverage of comments

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Apr 30 09:10:50 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45757

            Bug ID: 45757
           Summary: line coverage shows coverage of comments
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hans at chromium.org
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk,
                    vsk at apple.com

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).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200430/0f8b964f/attachment.html>


More information about the llvm-bugs mailing list