From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27418 invoked by alias); 16 Dec 2013 14:38:41 -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 27362 invoked by uid 55); 16 Dec 2013 14:38:37 -0000 From: "joseph at codesourcery dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/59448] Code generation doesn't respect C11 address-dependency Date: Mon, 16 Dec 2013 14:38:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: joseph at codesourcery dot com X-Bugzilla-Status: UNCONFIRMED 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: 2013-12/txt/msg01386.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59448 --- Comment #5 from joseph at codesourcery dot com --- On Thu, 12 Dec 2013, algrant at acm dot org wrote: > demonstrates the same lack of ordering. You suggest that this might > be a problem with the atomic built-ins - and yes, if this had been a > load-acquire, it would be a problem with the built-in not introducing a > barrier or using a load-acquire instruction. But for a load-consume on > this architecture, no barrier is necessary to separate the load-consume > from a load that is address-dependent on it. The programmer wrote a > dependency but the compiler lost track of it. "address-dependent" is not a C standard concept. As far as I can tell, at least as regards C there are no such ordering constraints between non-atomic operations, only between operations at least one of which is atomic - thus, it is the responsibility of the atomic built-in functions to ensure whatever ordering may be required. (Whereas the parts of the memory model defining what counts as a "memory location" *do* have implications in the absence of atomics, restricting the code sequences that can be used for struct modifications and preventing speculative stores.) > It's not necessary to demonstrate failure - there's an architectural > race condition here. Even if it doesn't fail now there's no guarantee > it will never fail on future more aggressively reordering cores. You still need to provide a testcase (a complete program that can be compiled and linked with current GCC) that (a) does not show undefined behavior, (b) that, you justify by reference to the standard definitions and how they apply to source code constructs, must exhibit specific observable behavior (values printed, assertions passed, etc. - *not* just ordering of loads at the architectural level), and (c) that, you justify by reference to the architecture definition if not to actual observed failure, could fail to meet the requirements for observable behavior, given the code generated by GCC and the behavior permitted by the architecture for that code. I am unable to tell what code you envisage running in another thread or what observable failure you think could result from "lack of ordering", because you have not provided a complete testcase. Thus, I am unable to tell if there is a genuine bug here at all. The standard definitions associated with atomicity are extremely complicated; you need to be very careful about identifying exactly how particular definitions apply to particular source code constructs and so how you deduce the requirements on behavior of a particular program, for a bug report to be of any use.