[llvm-bugs] [Bug 45678] New: llvm-cov: wrong coverage for a loop statement within switch block

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Apr 26 07:50:44 PDT 2020


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

            Bug ID: 45678
           Summary: llvm-cov: wrong coverage for a loop statement within
                    switch block
           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 -v
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
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/9.3.0
Found candidate GCC installation:
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.3.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/9.3.0
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.3.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

$ clang -w -O0 -g -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|       |int main()
    2|      1|{
    3|      1|  int size = 4, ret = 0;
    4|      1|  
    5|      1|  switch (size)
    6|      1|  {
    7|      0|    for(;;)
    8|      3|    {
    9|      3|      ret++;
   10|      3|    case 3:
   11|      3|      ret++;
   12|      4|    case 4:
   13|      4|      if (size <= 1)
   14|      1|        break;
   15|      3|      size -= 1;
   16|      3|    }
   17|      1|  }
   18|      1|  return 0;
   19|      1|}


####
We found that, Line #7 is marked as not execute. However, Line 8,9,10,and 11
are both executed three times. The loop statement should executed at least
three times. 
For example, when we setting breakpoint at this small.c:7, lldb will stopped at
this statement as follows:


$ clang -g small.c; lldb ./a.out
(lldb) target create "./a.out"
Current executable set to '/home/yibiao/a.out' (x86_64).
(lldb) b small.c:7
Breakpoint 1: where = a.out`main + 106 at small.c:7:5, address =
0x000000000040117a
(lldb) run
Process 275921 launched: '/home/yibiao/cv-gcov/a.out' (x86_64)
Process 275921 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x000000000040117a a.out`main at small.c:7:5
   4      
   5      switch (size)
   6      {
-> 7        for(;;)
   8        {
   9          ret++;
   10       case 3:


$ cat small.c
int main()
{
  int size = 4, ret = 0;

  switch (size)
  {
    for(;;)
    {
      ret++;
    case 3:
      ret++;
    case 4:
      if (size <= 1)
        break;
      size -= 1;
    }
  }
  return 0;
}

-- 
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/20200426/38f9549a/attachment-0001.html>


More information about the llvm-bugs mailing list