[Bug c/69002] C front end should warn about undefined access to atomic structure or union
joseph at codesourcery dot com
gcc-bugzilla@gcc.gnu.org
Mon Dec 21 21:04:00 GMT 2015
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.
More information about the Gcc-bugs
mailing list