Re: Flags -g and -O give very different results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Michael P Friedlander wrote:
Thanks for pointing out various options, Andrew.

The behavior of a numerical code I'm working on varies
drastically depending on whether I've compiled it with
the  -g  or  -O  flags.

The code's behavior under -g is much more stable, and I'm
wondering if the -O flag is exposing a bug that I need to
fix.  Are there some gcc flags that I should try that might
guide me in finding the problem?  (I've already tried the
obvious  -Wall  which gives no warnings.)

If your code does something different with/without -g, then that's a
bug in gcc.  -g shouldn't make any difference to the behaviour of your
program.

-g makes no difference.

If your code does somethig different with -O, that's possibly a gcc
bug but it's probably a bug in your code.

-OO  and  -O  give different results.

If you use -fno-strict-aliasing and that makes a difference with -O,
then that's definitely a bug in your code.

I think you nailed it! With -fno-strict-aliasing, -O0 and -O give identical results. I tried -fstrict-aliasing with -Wstrict-aliasing=2, but gcc doesn't issue any warnings.

Any pointers for how to track this sort of thing down? What kind of things should I look for?

-fstrict-aliasing asserts that your code complies with the C standard on typed aliasing. Pointers to objects of incompatible type must not modify the same storage locations. Code which violated this restriction was common, prior to the time when gcc introduced this option.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux