public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug gcov-profile/97919] New: [GCOV]volatile member in struct lead to incorrect code coverage
@ 2020-11-20  1:52 yangyibiao at outlook dot com
  2020-11-20  9:15 ` [Bug gcov-profile/97919] " marxin at gcc dot gnu.org
  2020-11-20  9:16 ` marxin at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: yangyibiao at outlook dot com @ 2020-11-20  1:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97919
           Summary: [GCOV]volatile member in struct lead to incorrect code
                    coverage
           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
static unsigned int s_irq[10];

static struct S {
  volatile unsigned int slock;
  unsigned int irq;
} sp[10];

static __inline__ __attribute__((always_inline)) int f1(int irq)
{
  return ((irq == 2) ? 9 : irq);
}

void f(void)
{
  struct S *up;
  int i;

  for (i=0, up=sp; i<10; i++, up++)
    up->irq = f1(s_irq[i]);
}

int main(void){ f(); }


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

        -:    0:Source:test.c
        -:    0:Graph:test.gcno
        -:    0:Data:test.gcda
        -:    0:Runs:1
        -:    1:static unsigned int s_irq[10];
        -:    2:
        -:    3:static struct S {
        -:    4:  volatile unsigned int slock;
        -:    5:  unsigned int irq;
        -:    6:} sp[10];
        -:    7:
        -:    8:static __inline__ __attribute__((always_inline)) int f1(int
irq)
        -:    9:{
      10*:   10:  return ((irq == 2) ? 9 : irq);
        -:   11:}
        -:   12:
        1:   13:void f(void)
        -:   14:{
        -:   15:  struct S *up;
        -:   16:  int i;
        -:   17:
       11:   18:  for (i=0, up=sp; i<10; i++, up++)
       20:   19:    up->irq = f1(s_irq[i]);
        1:   20:}
        -:   21:
        1:   22:int main(void){ f(); }

################
We can found that Line 19 is wrongly marked as executed 20 times.
When debug this program in debugger, it only hit 10 time.



$ gcc --version; gcov --version
gcc (GCC) 10.0.1 20200419 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gcov (GCC) 10.0.1 20200419 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug gcov-profile/97919] [GCOV]volatile member in struct lead to incorrect code coverage
  2020-11-20  1:52 [Bug gcov-profile/97919] New: [GCOV]volatile member in struct lead to incorrect code coverage yangyibiao at outlook dot com
@ 2020-11-20  9:15 ` marxin at gcc dot gnu.org
  2020-11-20  9:16 ` marxin at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-11-20  9:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Invalid because __inline__ __attribute__((always_inline)) leads to an optimized
code. Please do not use it if you want to have precise coverage information.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug gcov-profile/97919] [GCOV]volatile member in struct lead to incorrect code coverage
  2020-11-20  1:52 [Bug gcov-profile/97919] New: [GCOV]volatile member in struct lead to incorrect code coverage yangyibiao at outlook dot com
  2020-11-20  9:15 ` [Bug gcov-profile/97919] " marxin at gcc dot gnu.org
@ 2020-11-20  9:16 ` marxin at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-11-20  9:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
*** Bug 97921 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-20  9:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20  1:52 [Bug gcov-profile/97919] New: [GCOV]volatile member in struct lead to incorrect code coverage yangyibiao at outlook dot com
2020-11-20  9:15 ` [Bug gcov-profile/97919] " marxin at gcc dot gnu.org
2020-11-20  9:16 ` marxin at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).