This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
More fun with aliasing - removing assignments?
- From: Harald van DÄk <truedfx at gentoo dot org>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 1 Aug 2005 23:47:35 +0200
- Subject: More fun with aliasing - removing assignments?
Hello,
I finally managed to track down the problem I've been having to this
short code:
typedef struct {
unsigned car;
unsigned cdr;
} cons;
void nconc (unsigned x, unsigned y) {
unsigned *ptr = &x;
while(!(*ptr & 3))
ptr = &((cons *)(*ptr))->cdr;
*ptr = y;
}
With gcc 4.0-20050728 on i686-pc-linux-gnu, compiling this with -O2
appears to remove the assignment to *ptr. (I didn't prepare an example
program, but it's verifiable with objdump.) Obviously, this code is
non-portable, but still, I don't see why this can happen. Would anyone
be kind enough to explain this to me? It works as expected with -O2
-fno-strict-aliasing.
Thanks for any replies,