[llvm-bugs] [Bug 37132] New: [LLVM-COV] Wrong coverage with far jump

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Apr 14 06:24:23 PDT 2018


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

            Bug ID: 37132
           Summary: [LLVM-COV] Wrong coverage with far jump
           Product: Runtime Libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: libprofile library
          Assignee: unassignedbugs at nondot.org
          Reporter: yangyibiao at nju.edu.cn
                CC: llvm-bugs at lists.llvm.org

$ clang -v
clang version 7.0.0- (trunk)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.1
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8.0.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.2.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8.0.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8.0.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

$ cat small.c
#include <setjmp.h>

void quux(jmp_buf buf) { longjmp(buf, 927); }

void baz(jmp_buf buf)
{
  jmp_buf local_buf;

  if (!setjmp(local_buf))
    quux(buf);
  else
    ;
}

int main()
{
  jmp_buf buf;

  if (!setjmp(buf))
    baz(buf);

  return 0;
}

$ clang -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.gcov; cat small.gcov
    1|       |#include <setjmp.h>
    2|       |
    3|      1|void quux(jmp_buf buf) { longjmp(buf, 927); }
    4|       |
    5|       |void baz(jmp_buf buf)
    6|      1|{
    7|      1|  jmp_buf local_buf;
    8|      1|
    9|      1|  if (!setjmp(local_buf))
   10|      1|    quux(buf);
   11|      0|  else
   12|      0|    ;
   13|      1|}
   14|       |
   15|       |int main()
   16|      1|{
   17|      1|  jmp_buf buf;
   18|      1|
   19|      1|  if (!setjmp(buf))
   20|      1|    baz(buf);
   21|      1|
   22|      1|  return 0;
   23|      1|}

Line #13 is wrongly marked as executed. 
when call the quux function, the function will dirrectly jump to the main
function. Thus, the else block and the rest baz function will not executed.
Therefore, Line #13 should be not marked as executed. 


Coverage report from gcov for reference:
        -:    1:#include <setjmp.h>
        -:    2:
        1:    3:void quux(jmp_buf buf) { longjmp(buf, 927); }
        -:    4:
        1:    5:void baz(jmp_buf buf)
        -:    6:{
        -:    7:  jmp_buf local_buf;
        -:    8:
        1:    9:  if (!setjmp(local_buf))
        1:   10:    quux(buf);
        -:   11:  else
        -:   12:    ;
    #####:   13:}
        -:   14:
        1:   15:int main()
        -:   16:{
        -:   17:  jmp_buf buf;
        -:   18:
        1:   19:  if (!setjmp(buf))
        1:   20:    baz(buf);
        -:   21:
        1:   22:  return 0;
        -:   23:}

In gcov, the 13th line is marked as "#####" not executed.

-- 
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/20180414/664dce18/attachment.html>


More information about the llvm-bugs mailing list