This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/69002] C front end should warn about undefined access to atomic structure or union
- From: "joseph at codesourcery dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 21 Dec 2015 21:04:49 +0000
- Subject: [Bug c/69002] C front end should warn about undefined access to atomic structure or union
- Auto-submitted: auto-generated
- References: <bug-69002-4 at http dot gcc dot gnu dot org/bugzilla/>
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.