<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [LLVM-COV] Wrong coverage with far jump"
   href="https://bugs.llvm.org/show_bug.cgi?id=37132">37132</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[LLVM-COV] Wrong coverage with far jump
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Runtime Libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>libprofile library
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>yangyibiao@nju.edu.cn
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ 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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>