warning: dereferencing type-punned pointer will break strict-aliasing rules
Brian Dessent
brian@dessent.net
Tue Jul 24 23:14:00 GMT 2007
Jeffrey Holle wrote:
> On release builds, wxWidgets code emits a lot of these warnings:
> warning: dereferencing type-punned pointer will break strict-aliasing
> rules
>
> Questions:
>
> 1. Are these warnings benign? If so can they be suppressed?
> 2. If not, what level of optimization should I regress to avoid these
> warnings?
I would certainly not ignore them. They indicate that the code being
compiled probably violates the ISO C standard rules for type aliasing,
which means there's a very real chance that gcc will generate code that
does something very different than what the author intended as this is
the realm of undefined behavior. With earlier versions of gcc you could
get away with it, and in fact there is a great deal of code out there
that is technically invalid C due to violating this aspect of the
standard. But nobody really cared until newer versions of gcc started
actually using a type-based alias system to perform optimizations that
were not possible before.
The best bet is to fix the invalid code. The next best thing is
probably -fno-strict-aliasing. This is a frequent and somewhat
sensitive topic on this mailing list, so I suggest you read the past
threads, e.g.
<http://www.google.com/search?num=100&q=site%3Agcc.gnu.org+inurl%3Aml+inurl%3A%22gcc-help%22+strict+aliasing+rules>.
Brian
More information about the Gcc-help
mailing list