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

fw at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Dec 21 17:58:00 GMT 2015


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

--- Comment #5 from Florian Weimer <fw at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #4)
> The footnote to 6.5.2.3/5 says "Members can be safely accessed using a
> non-atomic object which is assigned to or from the atomic object."  Does it
> mean that the following is OK?

Yes, I think this is how this language construct is supposed to be used.

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

Should be:

void
write2 (_Atomic S *p, int x)
{
  S s = {.x = x};
  *p = s;
}

write1 is a bit nonsensical.


More information about the Gcc-bugs mailing list