[llvm-bugs] [Bug 37124] New: [LLVM-COV] wrong coverage with switch-case statement when some case is empty

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Apr 13 10:12:54 PDT 2018


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

            Bug ID: 37124
           Summary: [LLVM-COV] wrong coverage with switch-case statement
                    when some case is empty
           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 <stdio.h>

static int func(int i) {
  int a = 0;
  switch (i) {
    case 8:
      printf("8\n");
      a = 6;
    case 0:
      ;
    case 3:
      ;
    case 2:
      printf("2\n"); break;
    case 1:
      ;
    case 7: a = 7;
    case 9: printf("9\n"); break;
    default: printf("4 or 5 or 6\n"); a = 1;
  }
  return a;
}


int main() {
  int i;
  for (i = 0; i < 10; ++i)
    func(i);
  return 0;
}

$ clang -w -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
2
9
2
2
4 or 5 or 6
4 or 5 or 6
4 or 5 or 6
9
8
2
9
    1|       |#include <stdio.h>
    2|       |
    3|     10|static int func(int i) {
    4|     10|  int a = 0;
    5|     10|  switch (i) {
    6|     10|    case 8:
    7|      1|      printf("8\n");
    8|      1|      a = 6;
    9|      2|    case 0:
   10|      2|      ;
   11|      3|    case 3:
   12|      3|      ;
   13|      4|    case 2:
   14|      4|      printf("2\n"); break;
   15|      3|    case 1:
   16|      1|      ;
   17|      2|    case 7: a = 7;
   18|      3|    case 9: printf("9\n"); break;
   19|      3|    default: printf("4 or 5 or 6\n"); a = 1;
   20|     10|  }
   21|     10|  return a;
   22|     10|}
   23|       |
   24|       |
   25|      1|int main() {
   26|      1|  int i;
   27|     11|  for (i = 0; i < 10; ++i)
   28|     10|    func(i);
   29|      1|  return 0;
   30|      1|}

Line #6  is with wrong execution times, the correct mark should be "1".
Line #15 is with wrong execution times, the correct mark should be "1".

-- 
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/20180413/ab3728e3/attachment-0001.html>


More information about the llvm-bugs mailing list