This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/69002] New: C front end should warn about undefined access to atomic structure or union


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

            Bug ID: 69002
           Summary: C front end should warn about undefined access to
                    atomic structure or union
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fw at gcc dot gnu.org
  Target Milestone: ---

The following code currently compiles without warnings (apart from the
-Wunused-but-set-parameter warning), but the standard says in 6.5.2.3/5 that
this results in undefined behavior.

typedef _Atomic struct
{
  int x;
} S;


int
read1 (S p)
{
  return p.x;
}

int
read2 (S *p)
{
  return p->x;
}

void
write1 (S p, int x)
{
  p.x = x;
}

void
write2 (S *p, int x)
{
  p->x = x;
}

(Plus the same test for union instead of struct.)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]