[llvm-bugs] [Bug 45845] New: llvm-cov: wrong coverage for statement in a loop

via llvm-bugs llvm-bugs at lists.llvm.org
Fri May 8 10:13:50 PDT 2020


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

            Bug ID: 45845
           Summary: llvm-cov: wrong coverage for statement in a loop
           Product: Runtime Libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: libprofile library
          Assignee: unassignedbugs at nondot.org
          Reporter: yangyibiao at hust.edu.cn
                CC: llvm-bugs at lists.llvm.org

$ clang --version
clang version 11.0.0 (/home/yibiao/.cache/yay/llvm-git/llvm-project
871beba234a83a2a02da9dedbd59b91a1bfbd7af)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ clang -O0 -fcoverage-mapping -fprofile-instr-generate=small.profraw small.c;
./a.out; llvm-profdata merge small.profraw -o small.profdata; llvm-cov show
a.out -instr-profile=small.profdata small.c > small.c.lcov; cat small.c.lcov
    1|       |void foo(int y)
    2|      1|{
    3|      1|  if (y) 
    4|      0|    exit(1);
    5|      1|  exit(0);
    6|      1|}
    7|       |
    8|       |void main()
    9|      1|{
   10|      1|  int x = 1, y = 0;
   11|      2|  while(1) {
   12|      1|    if (x)
   13|      1|      foo(y);
   14|      1|    x++;
   15|      1|  }
   16|      1|}


****
Line 14 is wrongly marked as executed. However, the program exit in foo
function. Thus, Line 11 is not executed. This is confirmed in lldb as follow:

$ clang -w -g small.c; lldb a.out
(lldb) target create "a.out"
Current executable set to '/home/yibiao/Decov/a.out' (x86_64).
(lldb) b 14
Breakpoint 1: where = a.out`main + 40 at small.c:14:6, address =
0x0000000000401188
(lldb) r
Process 446347 launched: '/home/yibiao/Decov/a.out' (x86_64)
Process 446347 exited with status = 0 (0x00000000)

We can find that process exit thus, the breakpoint at Line 14 is not hit by
lldb.

-- 
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/20200508/0abbc830/attachment-0001.html>


More information about the llvm-bugs mailing list