------- Additional Comments From gdr at integrable-solutions dot net 2005-07-15 07:51 ------- Subject: Re: gcc -O2 discards cast to volatile
"neroden at gcc dot gnu dot org" <[EMAIL PROTECTED]> writes: [...] | of an arbitrary memory address. If the "underlying object" has | to be volatile, how do we make it volatile? Can we simply create a new | "underlying object" by throwing in a temporary pointer variable? Is something | like the following sufficient to force an access? | | static inline unsigned char myMmioIn8(volatile void* base, | const unsigned long offset) | { | volatile CARD8 * tmp = (CARD8*)base + offset; | return *tmp; | } If is fragile. If the compiler does more aggressive inline (which I hope 4.0 doesn't, but 4.x may at some point) and discover that the chains of conversion started with something it thinks really not volatile, then it would behave the same way as with the macro. | # define MMIO_IN8(base, offset) myMmioIn8(base, offset) | | If that's not sufficient, I don't see any way to accomplish the required | behavior under gcc 4.0 (without massive rewriting of the X.org code), so I | hope it is. I've come to believe that GCC's current choice is needlessly unhelpful. I think it is much more reasonable to have GCC leave its optimizer fingers out of the access through volatile lvalue, whether the object behind is really defined volatile of not -- GCC cannot know and the programmer cannot if is the "object behind" is actually never defined, but is mapped to a memory. Unfortunately, I don't know the extent of the GCC code that needs to be fixed so I don't know whether it is fixable in 4.0. -- Gaby -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22278