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

            Bug ID: 97924
           Summary: [GCOV]incorrect coverage for "?:" statement falls in
                    different lines
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yangyibiao at outlook dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ cat test.c

#include <string.h>

struct S { int *obj; };

void *foo() { return 0; }

void bar(struct S *r)
{
  r->obj = 
     (int *)(r->obj != ((void *)0) ? ({void *v=0; v;}) : foo());
}

int main(void)
{
  struct S r;
  memset(&r, 0, sizeof(struct S));
  bar(&r);
}


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

        -:    0:Source:test.c
        -:    0:Graph:test.gcno
        -:    0:Data:test.gcda
        -:    0:Runs:1
        -:    1:
        -:    2:#include <string.h>
        -:    3:
        -:    4:struct S { int *obj; };
        -:    5:
        1:    6:void *foo() { return 0; }
        -:    7:
        1:    8:void bar(struct S *r)
        -:    9:{
       2*:   10:  r->obj = 
       1*:   11:     (int *)(r->obj != ((void *)0) ? ({void *v=0; v;}) :
foo());
        1:   12:}
        -:   13:
        1:   14:int main(void)
        -:   15:{
        -:   16:  struct S r;
        1:   17:  memset(&r, 0, sizeof(struct S));
        1:   18:  bar(&r);
        -:   19:}


###############
Line 10 is marked as executed 2 times. However, it should be execute only once
as when debut this program in debugger, it hit only once.

I am not sure it is a bug in coverage profiler as the "?:" statement is at
another line of code.

Reply via email to