[Bug gcov-profile/101410] New: [Gcov] wrong coverage for a "default" statement

byone.heng at gmail dot com gcc-bugzilla@gcc.gnu.org
Sun Jul 11 07:17:39 GMT 2021


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

            Bug ID: 101410
           Summary: [Gcov] wrong coverage for a "default" 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
——————————————————————————

static const unsigned long int true_var = 1;
volatile long int false_var = 0;

int
main (int argc, char **argv)
{
  int *ptr = 0;

  for (unsigned i = 0; i < 2; i++)
    {
      switch (argc)
        {
        case 11111:;
          int a;
          if( true_var > 0 )
        {
        ptr = &a;
          break;
        }
          {
            default:
              ptr = &a;
              *ptr = 12345;
            case 222222:
            my_label:
              ptr = &a;
              break;
          }
        }
    }

  if (argc == 333333)
    goto my_label;

  return 0;
}


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


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

        -:    4:static const unsigned long int true_var = 1;
        -:    5:volatile long int false_var = 0;
        -:    6:
        -:    7:int
        1:    8:main (int argc, char **argv)
        -:    9:{
        1:   10:  int *ptr = 0;
        -:   11:
        3:   12:  for (unsigned i = 0; i < 2; i++)
        -:   13:    {
        2:   14:      switch (argc)
        -:   15:        {
    #####:   16:        case 11111:;
        -:   17:          int a;
    #####:   18:          if( true_var > 0 )
        -:   19:          {
    #####:   20:            ptr = &a;
    #####:   21:            break;
        -:   22:          }
        -:   23:          {
        -:   24:            default:
        2:   25:              ptr = &a;
        2:   26:              *ptr = 12345;
        -:   27:            case 222222:
        2:   28:            my_label:
        2:   29:              ptr = &a;
        2:   30:              break;
        -:   31:          }
        -:   32:        }
        -:   33:    }
        -:   34:
        1:   35:  if (argc == 333333)
    #####:   36:    goto my_label;
        -:   37:
        1:   38:  return 0;
        -:   39:}
        -:   40:

Line 24 should be executed twice.


More information about the Gcc-bugs mailing list