[Bug gcov-profile/101409] New: [Gcov] the incorrect coverage of the "default” statement in the "if" statement

byone.heng at gmail dot com gcc-bugzilla@gcc.gnu.org
Sun Jul 11 06:43:48 GMT 2021


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

            Bug ID: 101409
           Summary: [Gcov] the incorrect coverage of the "default”
                    statement in the "if" statement
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: byone.heng at gmail dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$./gcc -v                                                                       
Using built-in specs.
COLLECT_GCC=./gcc
COLLECT_LTO_WRAPPER=/home/x/project/gcc/build/install/libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/home/x/project/gcc/build/install
--enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20210105 (experimental) (GCC)

$cat test.c
——————————————————————————

const int true_var = 1;
unsigned char false_var = 0;

int a;
void try_help () __attribute__ ((__noreturn__));
void try_help ()
{
}

int main ()
{
  switch (a)
    {
      case '1':
      case '2':
      case '3':
      case '4':
      case '5':
      case '6':
      case '7':
      case '8':
      case '9':
          break;
      if( true_var > 0 )
      {
      default:
          try_help ();
      }
    }
}

——————————————————————————


$gcc -O0 --coverage test.c;./a.out;gcov test;cat test.c.gcov

        -:    4:const int true_var = 1;
        -:    5:unsigned char false_var = 0;
        -:    6:
        -:    7:int a;
        -:    8:void try_help () __attribute__ ((__noreturn__));
        1:    9:void try_help ()
        -:   10:{
        1:   11:}
        -:   12:
        1:   13:int main ()
        -:   14:{
        1:   15:  switch (a)
        -:   16:    {
    #####:   17:      case '1':
        -:   18:      case '2':
        -:   19:      case '3':
        -:   20:      case '4':
        -:   21:      case '5':
        -:   22:      case '6':
        -:   23:      case '7':
        -:   24:      case '8':
        -:   25:      case '9':
    #####:   26:          break;
        -:   27:      if( true_var > 0 )
        -:   28:      {
        -:   29:      default:
        1:   30:          try_help ();
        -:   31:      }
        -:   32:    }
        -:   33:}

Line 29 should be executed one time.


More information about the Gcc-bugs mailing list