[Bug gcov-profile/90438] New: [GCOV] switch statement is not instrumented when "case" body is empty and only "default" body with statements

yangyibiao at nju dot edu.cn gcc-bugzilla@gcc.gnu.org
Sun May 12 09:12:00 GMT 2019


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

            Bug ID: 90438
           Summary: [GCOV] switch statement is not instrumented when
                    "case" body is empty and only "default" body with
                    statements
           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: ---

$ gcov -v
gcov (GCC) 9.0.1 20190414 (experimental)
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.

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

        -:    0:Source:small.c
        -:    0:Graph:small.gcno
        -:    0:Data:small.gcda
        -:    0:Runs:1
        1:    1:int f(int i)
        -:    2:{
        -:    3:  int res;
        -:    4:
        -:    5:  switch (i)
        -:    6:    {
        -:    7:    case 5:
        -:    8:      // res = i - i;
        -:    9:      // break;
        -:   10:    default:
        1:   11:      res = i * 2;
        1:   12:      break;
        -:   13:    }
        -:   14:
        1:   15:  return res;
        -:   16:}
        -:   17:
        1:   18:int main(void)
        -:   19:{
        1:   20:  f(2);
        1:   21:  return 0;
        -:   22:}

I was wondering that Line #5 in this code should be an instrumentation site.
Thus, I think this line should be marked as executed. 
When Line #8 and Line #9 are not removed, Line #5 is became an instrumentation
site as follows:

$ gcc -O0 -g --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov
File 'small.c'
Lines executed:75.00% of 12
Creating 'small.c.gcov'

        -:    0:Source:small.c
        -:    0:Graph:small.gcno
        -:    0:Data:small.gcda
        -:    0:Runs:1
        1:    1:int f(int i)
        -:    2:{
        -:    3:  int res;
        -:    4:
        1:    5:  switch (i)
        -:    6:    {
    #####:    7:    case 5:
    #####:    8:      res = i - i;
    #####:    9:      break;
        1:   10:    default:
        1:   11:      res = i * 2;
        1:   12:      break;
        -:   13:    }
        -:   14:
        1:   15:  return res;
        -:   16:}
        -:   17:
        1:   18:int main(void)
        -:   19:{
        1:   20:  f(2);
        1:   21:  return 0;
        -:   22:}


More information about the Gcc-bugs mailing list