This is the mail archive of the gcc@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: C++ aliasing problem (noticed with -O2 -march=athlon)


On Dec  9, 2002, Jakub Bogusz <qboosh@pld.org.pl> wrote:

> "void*" should be valid alias for "unsigned int*", so
> isn't "void*&" vs "unsigned int*&" case similar?

Even though a void* can point to an unsigned int, you can't reference
it (you can't ever dereference a void*).  Arranging for a void** to
point to an unsigned* is asking for trouble, since dereferencing the
void** does violate aliasing rules, since void* and unsigned* are
different, unrelated types.  You could have a void* point to an
unsigned*, since the address of the unsigned* can be cast to void*,
just like any address, but you'd have to cast the pointer back to
unsigned** before you could dereference it.

For short: you're violating aliasing rules, and GCC is not in error
when it reorders the operations as it does on athlon.  It doesn't fail
on i686 out of luck.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer


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