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 01:53:56 -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 01:53 -------
[ see https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=162274 ]
I feel that he gcc documentation promises that there will be an access. The
documentation can change, but it is a contract between the implementer and the C
programmer. Breaking a contract is not very nice. Especially when it can cause
quiet subtle breakage of a program.
"info gcc" node "Volatiles" with title "6.1 When is a Volatile Object Accessed?"
clearly says:
<<Less obvious expressions are where something which looks like an access
is used in a void context. An example would be,
volatile int *src = SOMEVALUE;
*src;
With C, such expressions are rvalues, and as rvalues cause a read of
the object, GCC interprets this as a read of the volatile being pointed
to.>>
Now it turns out that gcc4 does *not* optimize away the access in:
void test(char *addr)
{
volatile char *t = addr;
(void) (*t);
}
Surely the motivating example in this bugzilla entry should be covered by the
same logic.
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |hugh at mimosa dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22278