This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/22278] gcc -O2 discards cast to volatile


------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]