This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++ aliasing problem (noticed with -O2 -march=athlon)
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Jakub Bogusz <qboosh at pld dot org dot pl>
- Cc: gcc at gcc dot gnu dot org
- Date: 10 Dec 2002 04:13:08 -0200
- Subject: Re: C++ aliasing problem (noticed with -O2 -march=athlon)
- Organization: GCC Team, Red Hat
- References: <20021209205517.GA8048@satan.blackhosts>
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