From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26983 invoked by alias); 29 Jan 2015 00:05:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 26793 invoked by uid 48); 29 Jan 2015 00:04:53 -0000 From: "richard-gccbugzilla at metafoo dot co.uk" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/64843] miscompilation of atomic_fetch_add on atomic pointer type Date: Thu, 29 Jan 2015 00:05:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: documentation, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: richard-gccbugzilla at metafoo dot co.uk X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-01/txt/msg03336.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64843 --- Comment #5 from Richard Smith --- (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, 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.