This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Could the following bug have been detected by a suitable compiler warning.


Hi Toon,

I guess it is possible, but wouldn't you get a lot of false messages,
for instance
with this type of code:

do while (barray(i) > 0.0 )
    a = array(i)
    i = i + 1
enddo

Here you look for a value in an array "array" that corresponds to the
last element in a
second array that complies to some condition. The last value of a is
what you want.
Perhaps not the most elegant or the most practical example, but I can imagine
this causing confusion.

Regards,

Arjen

2012/4/12 Toon Moene <toon@moene.org>:
> Last year I fixed (and Tobias B. followed up with another fix) the inability
> of gfortran to initialize automatic arrays with SNaN's, to detect the use of
> uninitialized automatic arrays by using the compiler options
> -finit-real=snan -ffpe-trap=invalid.
>
> Unfortunately, if you try to protect the universe from fools, the fools will
> prove themselves able to come up with other ways to make you hunt for the
> unknown.
>
> The following is what spurred a multi-week bug hunt by various people in our
> Numerical Weather Prediction project:
>
> DO I = 1, NLON ? ! Loop over longitudes
> ? ...
> ? A = <some expression involving several arrays indexed by I>
> ? ...
> ? <with no use of A anywhere in the loop>
> ? ...
> ENDDO
> ...
> <some intermediate code>
> ...
> DO I = 1, NLON
> ? ...
> ? <an array indexed by I> = A
> ? ...
> ENDDO
>
> Of course the obvious solution (as we know *now*) is to make A an array of
> 1:KLON, instead of a scalar [this whole problem might have originated when a
> single loop was split up into two - in the single loop you can use a scalar
> this way]
>
> Now the question is: Obviously, what happens to A in the first loop is
> nonsense - without a use of A the assignment is basically a no-op.
>
> Is it possible to detect this and warn for it ?
>
> --
> Toon Moene - e-mail: toon@moene.org - phone: +31 346 214290
> Saturnushof 14, 3738 XG ?Maartensdijk, The Netherlands
> At home: http://moene.org/~toon/; weather: http://moene.org/~hirlam/
> Progress of GNU Fortran: http://gcc.gnu.org/wiki/GFortran#news


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]