This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/22278] gcc -O2 discards cast to volatile
- From: "hugh at mimosa dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Jul 2005 05:40:12 -0000
- Subject: [Bug c/22278] gcc -O2 discards cast to volatile
- References: <20050702164323.22278.olivier.baudron@m4x.org>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From hugh at mimosa dot com 2005-07-03 05:40 -------
Simple rule about const and volatile qualifiers (not restrict): the program can
manipulate pointer values with and without their qualifiers. But when the
program accesses an object that is a volatile object (i.e. defined, created, or
fundamentally volatile), it must be via a volatile lvalue. And when the program
accesses an object that was created const (defined, created, or fundamentally
const), then it must not be modifying it.
Optimizers must not presume more. Well, there is a tricky rule about aliasing
in N1124 section 6.5 (see footnote 74 on page 68), based on the unqualified
types. But we're only talking about qualifiers. And another about multiple
modifications between sequence points -- again, not relevant here.
So I think that gcc4 is wrong for this case: the access should not be optimized out.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22278