More fun with aliasing - removing assignments?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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,


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux