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] C front end should warn about undefined access to atomic structure or union


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

--- Comment #8 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
On Mon, 21 Dec 2015, mpolacek at gcc dot gnu.org wrote:

> int
> read1 (_Atomic S p)
> {
>   S s = p;
>   return s.x;

That's fine.

> read2 (_Atomic S *p)
> {
>   S *s = p;

No, assignment / initialization etc. between pointer types differing in 
_Atomic in their target types is not permitted.

You need to do e.g.

  S s = *p;
  return s.x;

(which involves an atomic load of the whole structure).

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

Again, not valid.  Storing atomically to a member of an atomic structure 
probably requires a compare-exchange loop.

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