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 gcc2eran at tromer dot org  2005-07-03 04:14 -------
(In reply to comment #30)
> | OK. Then the volatile-stripping direction can be handled arbitrarily.
> 
> I do not understand that comment.

I meant that we were mostly concerned about what the standard says about the
effect of casting (say) int* into volatile int*, but the other directly is
simply undefined. 

Still, consider the following variant:

  void quux(int *bar) {
    *(volatile int*)bar = 42;
  }

  volatile int foo;
  quux((int*)&foo);

This time there is no "attempt [...] to refer to an object defined with a
volatile-qualified type through use of an lvalue with non-volatile-qualified
type". So why does gcc 4.0.0 -O3 still optimize away the assignment? And how
would you fix that with an approach that construes the standard to require
following the type of the "real" object?

Could the standard intend something so convoluted, when the interpretation in
comment 23 makes things perfectly sensible, well-defined and (in principle) easy
to implement?


-- 


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]