[llvm-bugs] [Bug 37083] New: [LLVM-COV] wrong coverage for a label pointed by a static pointer in a static function

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 10 23:32:27 PDT 2018


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

            Bug ID: 37083
           Summary: [LLVM-COV] wrong coverage for a label pointed by a
                    static pointer in a static function
           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

$ 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.

-- 
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/20180411/eb9897a3/attachment.html>


More information about the llvm-bugs mailing list