Flags -g and -O give very different results

Michael P Friedlander mpf@cs.ubc.ca
Sun Jul 2 19:28:00 GMT 2006


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?

Thanks!
--Michael



More information about the Gcc-help mailing list