https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85337

            Bug ID: 85337
           Summary: [GCOV] inconsistent coverage in swith-case statement
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yangyibiao at nju dot edu.cn
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

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;
}
root@localhost:~/ccv# gcc --coverage small.c; ./a.out; gcov-8 small.c; cat
small.c.gcov
2
9
2
2
4 or 5 or 6
4 or 5 or 6
4 or 5 or 6
9
8
2
9
File 'small.c'
Lines executed:100.00% of 17
Creating 'small.c.gcov'

        -:    0:Source:small.c
        -:    0:Graph:small.gcno
        -:    0:Data:small.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:
        -:    2:#include <stdio.h>
        -:    3:
       10:    4:static int func(int i) {
       10:    5:  int a = 0;
       10:    6:  switch (i) {
        1:    7:    case 8:
        1:    8:      printf("8\n");
        1:    9:      a = 6;
        4:   10:    case 0:
        -:   11:      ;
        -:   12:    case 3:
        -:   13:      ;
        -:   14:    case 2:
        4:   15:      printf("2\n"); break;
        2:   16:    case 1:
        -:   17:      ;
        2:   18:    case 7: a = 7;
        3:   19:    case 9: printf("9\n"); break;
        3:   20:    default: printf("4 or 5 or 6\n"); a = 1;
        -:   21:  }
       10:   22:  return a;
        -:   23:}
        -:   24:
        -:   25:
        1:   26:int main() {
        -:   27:  int i;
       11:   28:  for (i = 0; i < 10; ++i)
       10:   29:    func(i);
        1:   30:  return 0;
        -:   31:}

Line #10, Line #12, Line #14 are respectively marked as "4", "-", "-". 
I am not claim that this is a bug since I am not sure whether it is the default
behavior of gcov.

Reply via email to