From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6222 invoked by alias); 3 Jul 2005 07:09:27 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 6198 invoked by uid 48); 3 Jul 2005 07:09:23 -0000 Date: Sun, 03 Jul 2005 07:09:00 -0000 Message-ID: <20050703070923.6197.qmail@sourceware.org> From: "schlie at comcast dot net" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20050702164323.22278.olivier.baudron@m4x.org> References: <20050702164323.22278.olivier.baudron@m4x.org> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c/22278] gcc -O2 discards cast to volatile X-Bugzilla-Reason: CC X-SW-Source: 2005-07/txt/msg00258.txt.bz2 List-Id: ------- Additional Comments From schlie at comcast dot net 2005-07-03 07:09 ------- (In reply to comment #35) > Subject: Re: gcc -O2 discards cast to volatile I apologize for interjecting, but wanted to verify my perception the conclusions reached; are they essentially?: - although an object referenced through a qualified lvalue which differs from that object's declaration may result in an undefined behavior (as an implementation may specifically allocate objects based upon their respective qualification, therefore may result in an unanticipated behavior if referenced as being dissimilarly qualified). - that object should be effectively be treated as specified by that qualified lvalue unless the compiler knows factually that it's correspondingly implied side effects will not affect the program's otherwise specified behavior. (where lvalue in this context is any object's reference, which may refer to either a source, or destination value.) Therefore: int i; const int ci: volatile int vi; *(int*)&ci = 0; // should treat ci as int, although may result in // unexpected behavior as const may be read-only. int* foo(const int * ci){ return (int*)ci; } *(foo(ci)) = 0; // as above. *(int)&vi = 0; // should treat as non-volatile, although may // may result in unexpected behavior if special // volatile things happen when a volatile allocated // object is physically addressed for example. *(volatile int*)&i = 0; // should treat as volatile, although may // result in unexpected behavior if true // volatile objects need to be declared as // such to be specially allocated to satisfy // an implementation's defined behavior. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22278