[Bug gcov-profile/90420] [GCOV] wrong coverage with "-O3" or "-O2" optimizations for function call

marxin at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri May 10 06:23:00 GMT 2019


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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2019-05-10
     Ever confirmed|0                           |1

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
> $ gcc -O3 -g --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov
> File 'small.c'
> Lines executed:78.57% of 14
> Creating 'small.c.gcov'
> 
>         -:    0:Source:small.c
>         -:    0:Graph:small.gcno
>         -:    0:Data:small.gcda
>         -:    0:Runs:1
>         -:    1:#define N 1000
>         -:    2:
>         -:    3:int argc = 1;
>         -:    4:
>     #####:    5:int func (int *p, int *q) {
>     1001*:    6:  int x = 0;
>     #####:    7:  for (int i = 0; i < N; i++) { 
>     1000*:    8:    x += (q[i] + p[i]);
>         -:    9:  }
>        1*:   10:  return x;
>         -:   11:}
>         -:   12:
>         1:   13:int main ()
>         -:   14:{
>         1:   15:  int x = 0;
>         1:   16:  int A1[N], A2[N];
>         -:   17:
>      1001:   18:  for (int i = 0; i < N; i++) {
>      1000:   19:    A1[i] = 5 + argc;
>      1000:   20:    A2[i] = 1;
>         -:   21:  }
>         -:   22:  
>      1001:   23:  x = func (A1, A2);
>         -:   24:
>         1:   25:  if (x != N * 7)
>     #####:   26:    return 1;
>         -:   27:
>         -:   28:  return 0;
>         -:   29:}
> 
> 
> When using "-O3" optimization, Line #6 and Line #22 are wrongly marked as

I can't see Line #22 being executed.

With 9.1.0 I see:

        -:    0:Source:pr90420.c
        -:    0:Graph:pr90420.gcno
        -:    0:Data:pr90420.gcda
        -:    0:Runs:1
        -:    1:#define N 1000
        -:    2:
        -:    3:int argc = 1;
        -:    4:
    #####:    5:int func (int *p, int *q) {
        -:    6:  int x = 0;
    1001*:    7:  for (int i = 0; i < N; i++) { 
    1000*:    8:    x += (q[i] + p[i]);
        -:    9:  }
    #####:   10:  return x;
        -:   11:}
        -:   12:
        1:   13:int main ()
        -:   14:{
        -:   15:  int x = 0;
        -:   16:  int A1[N], A2[N];
        -:   17:
     1001:   18:  for (int i = 0; i < N; i++) {
     1000:   19:    A1[i] = 5 + argc;
     1000:   20:    A2[i] = 1;
        -:   21:  }
        -:   22:  
        -:   23:  x = func (A1, A2);
        -:   24:
        1:   25:  if (x != N * 7)
    #####:   26:    return 1;
        -:   27:
        -:   28:  return 0;
        -:   29:}

which should be reasonable good.


More information about the Gcc-bugs mailing list