This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

[Bug fortran/18998] Gfortran produces wrong output (c/f to g77)


------- Additional Comments From Tobias dot Schlueter at physik dot uni-muenchen dot de  2004-12-21 00:04 -------
Subject: Re:  Gfortran produces wrong output (c/f to g77)

Deji Akingunola wrote:
>>------- Additional Comments From tobi at gcc dot gnu dot org  2004-12-20 22:40 -------
>>The problem is an out-of-bounds array access to sa, note its dimensions and the
>>values the loop index takes on.
>>
> 
> I'm sorry I don't get the above, what do you mean by 'out-of-bound array
> access to sa' (what's sa). I wonder why it's tagged invalid while other
> compilers does successfully execute the same code. Does it mean one has
> to pass some special options to gfortran to produce the right result.
> Thanks.

The code has a bug.  It's not gfortran's fault that it doesn't work with
gfortran.  'sa' is an array in that code.  It is accessed out of bounds in the
loop of the main program.  This is caught at runtime, if the code is compiled
with '-fbounds-check'.  The problem only appears on i686 by hazard.  'The code
works if compiled with other compilers' doesn't mean 'the code is correct and
bug-free', unfortunately.

If you're still not convinced, lean back, look at the following five lines of
code (which are extracted from your testcase), and try to figure out what the
code means for all possible values of 'i'.
      parameter(n=8)
      real sa(n)
      do 20,i=1,2*n-1,2
         sa(i)=a(i)**2+a(i+1)**2
 20   continue

Regards,
- Tobi

ps I think you really want that loop to look like
  do i=2, 2*n, 2
      sa(i/2) = a(i-1)**2 + a(i)**2
  end do
or something similar.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18998


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