<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 the "for" and "setjmp""
   href="https://bugs.llvm.org/show_bug.cgi?id=51153">51153</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[LLVM-COV] Wrong coverage with the "for" and "setjmp"
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>cnwy1996@outlook.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ clang -v
clang version 11.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/wangyang/llvm-project/build/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

$ cat test.c
extern int strcmp(const char *, const char *);
extern char *strcpy(char *, const char *);
extern void abort(void);
extern void exit(int);

void *buf[20];

void __attribute__((noinline)) sub2(void) { __builtin_longjmp(buf, 1); }

int main() {
  char *p = (char *)__builtin_alloca(20);

  strcpy(p, "test");

  if (__builtin_setjmp(buf)) {
    if (strcmp(p, "test") != 0)
      abort();

    exit(0);
  }

  {
    int *q = (int *)__builtin_alloca(p[2] * sizeof(int));
    printf("Excuted!\n");
    int i;

    for (i = 0; i < p[2]; i++)
      q[i] = 0;

    while (1)
      sub2();
  }
}

$ clang -w -O0 -g -fcoverage-mapping -fprofile-instr-generate=test.profraw
test.c; ./a.out; llvm-profdata merge test.profraw -o test.profdata; llvm-cov
show a.out -instr-profile=test.profdata test.c > test.lcov; cat test.lcov
Excuted!
    1|       |#include<stdio.h>
    2|       |extern int strcmp(const char *, const char *);
    3|       |extern char *strcpy(char *, const char *);
    4|       |extern void abort(void);
    5|       |extern void exit(int);
    6|       |
    7|       |void *buf[20];
    8|       |
    9|      1|void __attribute__((noinline)) sub2(void) {
__builtin_longjmp(buf, 1); }
   10|       |
   11|      1|int main() {
   12|      1|  char *p = (char *)__builtin_alloca(20);
   13|      1|
   14|      1|  strcpy(p, "test");
   15|      1|
   16|      1|  if (__builtin_setjmp(buf)) {
   17|      1|    if (strcmp(p, "test") != 0)
   18|      0|      abort();
   19|      1|
   20|      1|    exit(0);
   21|      1|  }
   22|      0|
   23|      0|  {
   24|      0|    int *q = (int *)__builtin_alloca(p[2] * sizeof(int));
   25|      0|    printf("Excuted!\n");
   26|      0|    int i;
   27|      0|
   28|    115|    for (i = 0; i < p[2]; i++)
   29|    115|      q[i] = 0;
   30|      0|
   31|      1|    while (1)
   32|      1|      sub2();
   33|      0|  }
   34|      0|}



line 16 was executed twice, line 24 to 26 was executed once and line 28 was
executed 116 times.</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>