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]

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


"gcc2eran at tromer dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| ------- Additional Comments From gcc2eran at tromer dot org  2005-07-02 23:30 -------
| (In reply to comment #17)
| > Furthermore, the fundamental issue is whether this
| > 
| >    *(volatile int*) (int*) (&foo);
| > 
| > (or equivalent) where foo has been defined volatile int  should be
| > treated differently from 
| > 
| >    *(volatile int*) (&foo);
| > 
| >  or 
| > 
| >    foo;
| 
| How about this?
| 
|     int foo; 
|     *(volatile int*) (&foo);

It was included in my previous message.

| In other words, why should the compiler bother at all with the qualifiers of
| what the pointer "really" points to?

Because the language definition says that the compiler should preserve
a semantics and the compiler better bothers.

| It seems simplest and most natural to
| decree that any dereference of a pointer-to-volatile (regardless of
| its origin) is to be treated as volatile and thus never optimized
| away. In other words, "volatile" should treated as a property of the
| type of the pointer being dereferenced, not of the actual object
| being pointed to. 

but that is a fundamental departure from the language semantics.
Replace "volatile" with "const" -- both are qualifiers -- and observe
the disaster that would ensue.

The "volatile" cv-qualified is interesting in the sense that it is
fuzzily defined, but there are identities that the compiler must
preserve. 

-- Gaby


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