This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: warning: dereferencing type-punned pointer will break strict-aliasing rules
- From: Brian Dessent <brian at dessent dot net>
- To: jeffreyholle at bellsouth dot net
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 24 Jul 2007 16:14:41 -0700
- Subject: Re: warning: dereferencing type-punned pointer will break strict-aliasing rules
- References: <f8600s$ad$1@sea.gmane.org>
- Reply-to: gcc-help at gcc dot gnu dot org
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