This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Difference between -Ox and -fxxx flags
>>?
>> do 2000 i = 1,ilen
>> ? ? do 1990 k = 1,5
>> ? ? ? ? call qleval(5*i+k-5,j(k,i+ibeg),g,gj,nte)? ? ! j is a 2D array
>> 1990? continue
>> 2000 continue
>>
>> With "-O1" (or higher optimization levels), after many successful
> iterations of the above loops, i becomes negative and ilen becomes zero (it is a
> positive integer before the loop). Thus, one of the array indices in the
> "call qleval(...)" line is less than 1 (the lower bound) and the
> program crashes. I do not know why this occurs, but it doesn't occur when
> the program is compiled with ="-O0".
>
> You have a serious error somewhere in your code that is causing
> overwriting.? You need to find it and fix it.? Unfortunately, the
> symptoms of that class of error are completely unpredictable, and can
> even vary when you run the same executable twice with identical
> arguments with two consecutive commands.
>
> In Fortran, this is almost always due to exceeding the bounds of an
> array, sometimes because an index variable has got mangled.? That's
> where to start looking.
Thank you for the advice. Compiling with "-O1 -fbounds-check -fbacktrace"?
indeed identifies this as the cause.
>> However, when I compared the optimization settings between -O0 and -O1
> (using "gfortran -Q -Ox --help=optimizers") and then manually passed
> all of the additional "-fxxx" arguments that are enabled with -O1, the
> program runs correctly. It is this that has me confused. What is the difference
> between using "-O1" and passing all of the "-fxxx"
> arguments?
>
> That's typical of the class of error I am referring to.? You are not
> going to find it by tweaking compiler options, and your program may
> well start to fail with -O0 tomorrow, possibly with a completely
> different set of symptoms.? You are wasting your time tweaking the
> compiler options - sorry.
That was my suspicion, but I was confused because the program runs correctly?
when compile with "-O0 -fbounds-check -fbacktrace". The variables are not?
over-written, which I've verified by printing their values for each iteration.
Compiling with "-Wall" does highlight four lines in particular.
> The Fortran compiler with the best checking is NAG, and that would almost
> certainly pick up your error automatically - but it might reject your
> program for other reasons.? With gfortran, you should enable every
> error-detection option you can find and try again.? Sometimes memory
> checking tools or debuggers help.? But, however you do it, you will need
> to find and fix your bug.
Thanks for the advice! I'll hash this out with my colleagues.
Many thanks,
Rob