From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12044 invoked by alias); 2 Feb 2012 11:11:04 -0000 Received: (qmail 12034 invoked by uid 22791); 2 Feb 2012 11:11:03 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 02 Feb 2012 11:10:51 +0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/52080] Stores to bitfields introduce a store-data-race on adjacent data Date: Thu, 02 Feb 2012 11:11:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2012-02/txt/msg00210.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52080 --- Comment #10 from Richard Guenther 2012-02-02 11:08:56 UTC --- (In reply to comment #9) > OK, my minimal test case removed the "volatile" keyword by mistake. > > The real code in BTRFS has the volatile for the lock value which precedes the > bitfield, so the corresponding structure would be: > > struct x { > long a; > volatile unsigned int lock; /* <- note the "volatile" here */ > unsigned int full : 1; > }; > > Now, GCC should honour that the value of "lock" can change any time, so it must > not assume that writing back the same value a few cycles later is safe. volatiles on single structure members is of course under- (or even un-)specified. Consider struct x { int i : 1; volatile int j : 1; }; Where we clearly cannot access i without modifying j (but it's still valid C). So I don't think that a volatile member inside a non-volatile struct guarantees anything. Now, with struct x { long a; volatile unsigned int lock; unsigned int full : 1; }; void wrong(volatile struct x *ptr) { ptr->full = 1; } IA64 uses .mmi ld8.acq r14 = [r32] ;; nop 0 dep r14 = r15, r14, 32, 1 ;; .mib st8.rel [r32] = r14 which seems to be an attempt to work around this issue (albeit a possibly very slow one).