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

            Bug ID: 101417
           Summary: [Gcov] an unexecuted  if statement leads to incorrect
                    coverage of a return 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 volatile short int true_var = 1;
volatile long int false_var = 0;

int c = 1;

__attribute__ ((optimize (1)))
static int *foo (int *p)
{
  if( false_var > 0 )
  {
  return p;
  }
  return p;
}

int
main ()
{
  *foo (&c) = 2;
  return c - 2;
}


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


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

        -:    3:static const volatile short int true_var = 1;
        -:    4:volatile long int false_var = 0;
        -:    5:
        -:    6:int c = 1;
        -:    7:
        -:    8:__attribute__ ((optimize (1)))
        1:    9:static int *foo (int *p)
        -:   10:{
        1:   11:  if( false_var > 0 )
        -:   12:  {
        -:   13:  return p;
        -:   14:  }
        -:   15:  return p;
        -:   16:}
        -:   17:
        -:   18:int
        1:   19:main ()
        -:   20:{
        1:   21:  *foo (&c) = 2;
        1:   22:  return c - 2;
        -:   23:}

Line 15 should be executed.

Reply via email to