This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/64843] miscompilation of atomic_fetch_add on atomic pointer type
- From: "richard-gccbugzilla at metafoo dot co.uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 29 Jan 2015 00:04:49 +0000
- Subject: [Bug c/64843] miscompilation of atomic_fetch_add on atomic pointer type
- Auto-submitted: auto-generated
- References: <bug-64843-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64843
--- Comment #5 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
(In reply to joseph@codesourcery.com from comment #3)
> The first question is whether this code is actually valid.
To my reading, the C11 standard says that these operations must work on all
atomic integer types, must be disallowed on atomic_bool, and it's unspecified
if they work on any other type. However, since GCC allows them for an
atomic-qualified pointer, the other rules in 7.17.7.5 apply.
I'm not at all confident that is the intended reading, though: in the C++
specification, from which the C specification was derived, there are overloads
of atomic_fetch_add for each atomic-integral type, plus overloads for
atomic<T*>, making it mandatory to handle the pointer case. I think this is
merely a bug in C11's spec, and this wording should also allow pointers, but
AFAICS it's not in C11's DR list.