Re: Properly controlling CFLAGS/CXXFLAGS



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@xxxxxxxxxxxxx
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: New filesystem for Linux
    ... C standard defines that shifts by more bits than size of a type are ... and the results with your example depend on the gcc ... version and optimization level. ... There had been need of rain for many days. ...
    (Linux-Kernel)
  • Re: Code size with GCC
    ... I am working on GCC for ARM target.I built one executable with GCC. ... kept optimization level as -O2. ... newlib is one of the biggest culprits. ...
    (comp.sys.arm)
  • Re: New filesystem for Linux
    ... C standard defines that shifts by more bits than size of a type are ... |int main{ ... and the results with your example depend on the gcc ... version and optimization level. ...
    (Linux-Kernel)
  • Re: [PATCH] drivers/video/pmag-ba-fb.c: Improve diagnostics
    ... We'd been hurling all sorts of abuses on gcc for quite long (when it fails ... easy to write *genuinely* buggy code that still won't get any warnings, ... Compared to that some useless warnings are negligible. ... This way any error paths lacking initialisation are still ...
    (Linux-Kernel)
  • Re: Properly controlling CFLAGS/CXXFLAGS
    ... apparently breaks too many software packages. ... 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. ...
    (freebsd-hackers)