From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2321 invoked by alias); 24 Sep 2011 15:49:38 -0000 Received: (qmail 2304 invoked by uid 22791); 24 Sep 2011 15:49:35 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from asav3.lyse.net (HELO asav3.lyse.net) (81.167.37.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 24 Sep 2011 15:49:21 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by asav3.lyse.net (Postfix) with ESMTP id E781384140; Sat, 24 Sep 2011 17:49:19 +0200 (CEST) Received: from localhost.localdomain (unknown [79.161.10.130]) by asav3.lyse.net (Postfix) with ESMTP id 794A884158; Sat, 24 Sep 2011 17:49:19 +0200 (CEST) Received: from [192.168.0.60] (helo=[192.168.0.60]) by localhost.localdomain with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.50) id 1R7UTc-0007jA-No; Sat, 24 Sep 2011 17:49:16 +0200 Message-ID: <4E7DFB31.9010906@westcontrol.com> Date: Sat, 24 Sep 2011 15:49:00 -0000 From: David Brown User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1 MIME-Version: 1.0 Newsgroups: gmane.comp.gcc.devel To: John Regehr CC: gcc@gcc.gnu.org Subject: Re: Volatile qualification on pointer and data References: <4E7A3209.10508@gjlay.de> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2011-09/txt/msg00278.txt.bz2 On 24/09/2011 17:09, John Regehr wrote: >> What can't make sense is a /static/ "volatile const" which is >> /defined/ locally, rather than just declared. > > The code in question sounds well-defined (but probably poor style) to me. > > It is never OK to access a qualified object through an unqualified > pointer, but my understanding is that accessing an unqualified object > through a qualified pointer is well-defined and that the usual qualifier > rules apply to that access. > That is correct, and it is best to view the qualifiers as qualifying the access to the object, rather than the object itself. Qualifying the object just states the minimum qualifiers needed to legally access it. > David, is your "can't make sense" backed up by a standard? There is no > "lying to the compiler", there is only conforming and non-conforming code. > I don't think the standard has any restrictions on the combinations of qualifiers you can have on an object - thus it is legal C to have a "static volatile const" object, or to access a "static const" through a "volatile" access. But being legal C does not imply that it makes logical sense! Is it "lying to the compiler"? Perhaps not, but it is certainly saying two different things at the same time - they cannot both make sense, and I think the compiler is free to implement whichever of the conflicting ideas it wants. However, I am far from sure here - I am raising the question, not answering it. And while I think the compiler should be allowed to generate the optimised code of 4.6 (i.e., the change is not a bug IMHO), I fully understand the idea of generating the older, slower, but definitely correct code of 4.5. I am still trying to imagine a real-world use-case for declaring an object "static const" and later accessing it as "volatile". mvh., David From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3929 invoked by alias); 24 Sep 2011 15:49:51 -0000 Received: (qmail 3872 invoked by uid 22791); 24 Sep 2011 15:49:49 -0000 X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_00,RCVD_NUMERIC_HELO,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from lo.gmane.org (HELO lo.gmane.org) (80.91.229.12) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 24 Sep 2011 15:49:31 +0000 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1R7UTq-0001bt-56 for gcc@gcc.gnu.org; Sat, 24 Sep 2011 17:49:30 +0200 Received: from 79.161.10.130 ([79.161.10.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 24 Sep 2011 17:49:30 +0200 Received: from david by 79.161.10.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 24 Sep 2011 17:49:30 +0200 To: gcc@gcc.gnu.org From: David Brown Subject: Re: Volatile qualification on pointer and data Date: Sat, 24 Sep 2011 16:26:00 -0000 Message-ID: <4E7DFB31.9010906@westcontrol.com> References: <4E7A3209.10508@gjlay.de> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: gcc@gcc.gnu.org User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1 In-Reply-To: X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2011-09/txt/msg00279.txt.bz2 Message-ID: <20110924162600.EWHRCahyXIx2q8Z29rhagOOeysKhrBJU5OUPDaOTeqM@z> On 24/09/2011 17:09, John Regehr wrote: >> What can't make sense is a /static/ "volatile const" which is >> /defined/ locally, rather than just declared. > > The code in question sounds well-defined (but probably poor style) to me. > > It is never OK to access a qualified object through an unqualified > pointer, but my understanding is that accessing an unqualified object > through a qualified pointer is well-defined and that the usual qualifier > rules apply to that access. > That is correct, and it is best to view the qualifiers as qualifying the access to the object, rather than the object itself. Qualifying the object just states the minimum qualifiers needed to legally access it. > David, is your "can't make sense" backed up by a standard? There is no > "lying to the compiler", there is only conforming and non-conforming code. > I don't think the standard has any restrictions on the combinations of qualifiers you can have on an object - thus it is legal C to have a "static volatile const" object, or to access a "static const" through a "volatile" access. But being legal C does not imply that it makes logical sense! Is it "lying to the compiler"? Perhaps not, but it is certainly saying two different things at the same time - they cannot both make sense, and I think the compiler is free to implement whichever of the conflicting ideas it wants. However, I am far from sure here - I am raising the question, not answering it. And while I think the compiler should be allowed to generate the optimised code of 4.6 (i.e., the change is not a bug IMHO), I fully understand the idea of generating the older, slower, but definitely correct code of 4.5. I am still trying to imagine a real-world use-case for declaring an object "static const" and later accessing it as "volatile". mvh., David