<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 for a label pointed by a static pointer in a static function"
   href="https://bugs.llvm.org/show_bug.cgi?id=37083">37083</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[LLVM-COV] wrong coverage for a label pointed by a static pointer in a static function
          </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>$ cat small.c
#include <stdio.h>

static int doit(int x){
  __label__ lbl1;
  __label__ lbl2;
  static int jtab_init = 0;
  static void *jtab[2];

  if(!jtab_init) {
    jtab[0] = &&lbl1;
    jtab[1] = &&lbl2;
    jtab_init = 1;
  }

  if (jtab[x]==(&&lbl1))
    printf("call doit(%d) *jtab[x] at lbl1\n", x);
  if (jtab[x]==(&&lbl2))
    printf("call doit(%d) *jtab[x] at lbl2\n", x);

  goto *jtab[x];

lbl1:
  return 1;
lbl2:
  return 2;
}

int main(void){
  doit(0);
  doit(1);

  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
call doit(0) *jtab[x] at lbl1
call doit(1) *jtab[x] at lbl2
    1|       |#include <stdio.h>
    2|       |
    3|      2|static int doit(int x){
    4|      2|  __label__ lbl1;
    5|      2|  __label__ lbl2;
    6|      2|  static int jtab_init = 0;
    7|      2|  static void *jtab[2];
    8|      2|
    9|      2|  if(!jtab_init) {
   10|      1|    jtab[0] = &&lbl1;
   11|      1|    jtab[1] = &&lbl2;
   12|      1|    jtab_init = 1;
   13|      1|  }
   14|      2|
   15|      2|  if (jtab[x]==(&&lbl1))
   16|      1|    printf("call doit(%d) *jtab[x] at lbl1\n", x);
   17|      2|  if (jtab[x]==(&&lbl2))
   18|      1|    printf("call doit(%d) *jtab[x] at lbl2\n", x);
   19|      2|
   20|      2|  goto *jtab[x];
   21|      2|
   22|      2|lbl1:
   23|      1|  return 1;
   24|      1|lbl2:
   25|      1|  return 2;
   26|      0|}
   27|       |
   28|      1|int main(void){
   29|      1|  doit(0);
   30|      1|  doit(1);
   31|      1|
   32|      1|  return 0;
   33|      1|}

*****
Line #22 is wrongly marked as executed twice. However, from the output of the
program, a the second call to doit function. *jtab[x] is equal to lbl2,
therefore, Line #22 should be only executed once.</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>