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]

Re: warning: dereferencing type-punned pointer will break strict-aliasing rules


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


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