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

            Bug ID: 90092
           Summary: [GCOV] Wrong frequencies then the default label in
                    switch statement is followed with no statement
           Product: gcc
           Version: 9.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: ---

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/9.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --enable-languages=c,c++
--disable-multilib --prefix=/usr/local/gcc-trunk
Thread model: posix
gcc version 9.0.1 20190414 (experimental) (GCC)

$ cat small.c
int bar (int a)
{
  int ret = 0;
  switch (a)
  {
    case 1: ret = ret + 1; break;
    default:
      ;// ret = ret + 2;
  }

  return ret;
}

int main ()
{
  bar(1);
  return 0;
}

$ gcc -w -O0 --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov
File 'small.c'
Lines executed:100.00% of 9
Creating 'small.c.gcov'

        -:    0:Source:small.c
        -:    0:Graph:small.gcno
        -:    0:Data:small.gcda
        -:    0:Runs:1
        1:    1:int bar (int a)
        -:    2:{
        1:    3:  int ret = 0;
        1:    4:  switch (a)
        -:    5:  {
        1:    6:    case 1: ret = ret + 1; break;
        1:    7:    default:
        -:    8:      ;// ret = ret + 2;
        -:    9:  }
        -:   10:
        1:   11:  return ret;
        -:   12:}
        -:   13:
        1:   14:int main ()
        -:   15:{
        1:   16:  bar(1);
        1:   17:  return 0;
        -:   18:}

Line #7 is wrongly marked as executed. It should be not executed. 

I am not quite sure this should be reported as a new bug report. As there has
similar bug report 85179 while a label statement is followed with no
statements. 

When the "default:" statement is not empty, the result is correct as:
$ gcc -w -O0 --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov
File 'small.c'
Lines executed:80.00% of 10
Creating 'small.c.gcov'

        -:    0:Source:small.c
        -:    0:Graph:small.gcno
        -:    0:Data:small.gcda
        -:    0:Runs:1
        1:    1:int bar (int a)
        -:    2:{
        1:    3:  int ret = 0;
        1:    4:  switch (a)
        -:    5:  {
        1:    6:    case 1: ret = ret + 1; break;
    #####:    7:    default:
    #####:    8:      ret = ret + 2;
        -:    9:  }
        -:   10:
        1:   11:  return ret;
        -:   12:}
        -:   13:
        1:   14:int main ()
        -:   15:{
        1:   16:  bar(1);
        1:   17:  return 0;
        -:   18:}

Reply via email to