This is the mail archive of the gcc-help@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]

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,


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