[jhc] foreign ptr bugs

Korcan Hussein korcan_h at hotmail.com
Thu Dec 30 21:13:43 CET 2010


I've never had to deal with aliasing bugs before fortunately but I did come across an article about getting warning messages from gcc for code not adhering to strict-aliasing rules which is -Wstrict-aliasing=2 apparently this warning is not enabled by -Wall by default, I've tried this with the test code I attached earlier and I do get many of these type of messages:

"warning: dereferencing type-punned pointer will break strict-aliasing rules
warning: initialization from incompatible pointer type
warning: assignment from incompatible pointer type"

There is also the attribute __may_alias__ for structs.

I've also tried -fno-strict-aliasing without -fdebug and I do get different pointer values this time but the program does not work correctly, the image doesn't appear to get blitted to the screen buffer so I get a black window which means it is either a plain bug with generated code or another optimizations related to (strict-)aliasing messing things up or combination of both.

----------------------------------------
> From: john at repetae.net
> Date: Thu, 30 Dec 2010 04:42:14 -0800
> Subject: Re: [jhc] foreign ptr bugs
> To: korcan_h at hotmail.com
> CC: jhc at haskell.org
>
> I have narrowed it down to the -fstrict-aliasing optimization pass
> that is causing the bug. So it is likely that I am accidentally
> aliasing some memory location via two different pointer types. hmm...
> not sure how to proceed debugging this other than manual inspection of
> the generated assembly. Has anyone out there dealt with aliasing
> issues before? I'd prefer to figure out the root cause than just
> disable the optimization without understanding why it is needed.
>
> John
 		 	   		  


More information about the jhc mailing list