Properly controlling CFLAGS/CXXFLAGS
Erik Trulsson
ertr1013 at student.uu.se
Sat Dec 23 02:00:15 PST 2006
On Sat, Dec 23, 2006 at 02:38:15AM -0500, Joseph J. Damato wrote:
> > Garrett Cooper wrote:
> >
> > With '-O2' and better, '-fstrict-aliasing' is the default in newer
> > versions of GCC, AFAIK, but people tend to switch it off because it
> > apparently breaks too many software packages. Or at least those whose
> > code base dates back to times where '-fno-strict-aliasing' was the default
> > and people got away with certain nasty coding hacks that no longer work
> > with '-fstrict-aliasing'.
> >
>
> Well, -fno-strict-aliasing is pretty useful, especially if you want to do
> things with floating point. Not all code which requires
> -fno-strict-aliasing has "nasty coding hacks."
Well. no, the code might just have plain old bugs.
Any code that requires -fno-strict-aliasing is incorrect. (Or it might
indicate a bug in the compiler, but that is far less common.)
>
> As GCC says, the results are undefined when the flag is not passed. I have
> personally seen code that "looks" right but which results in very odd
> behavior with -O2, but works fine with any other optimization level.
The code might look right at first glance, but if it breaks with
-fstrict-aliasing then the code is almost certainly wrong.
It is very common that buggy code seems to work fine when compiled
with a low optimization level, but when compiled with higher optimization
the bugs are exposed.
>
> In situations like this, the flag is useful.
Yes, -fno-strict-aliasing is indeed useful to get some old, buggy code (as
well as some new, buggy code) to work until the code in question can be
fixed.
--
<Insert your favourite quote here.>
Erik Trulsson
ertr1013 at student.uu.se
More information about the freebsd-hackers
mailing list