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: ARRGH ... Re: Memory corruption on amd64 FreeBSD


On Thu, Sep 02, 2004 at 05:25:24PM +0100, Paul Brook wrote:
> On Thursday 02 September 2004 17:21, Steve Kargl wrote:
> > On Thu, Sep 02, 2004 at 12:34:23PM +0100, Paul Brook wrote:
> > > On Thursday 02 September 2004 03:18, Steve Kargl wrote:
> > > > On Wed, Sep 01, 2004 at 08:55:18PM +0200, Tobias Schl?ter wrote:
> > > > > Also, an out-of-bounds array access could be the problem here.
> > > >
> > > > I am soooooo embarassed.  I swear I've run this code
> > > > with bounds checking turned on in NAG's f95.  Well,
> > > > we now know what happens when memory goes from
> > > > x(1:n) and someone tries to address x(0:n-1).  To we
> > > > have a -fbounds-check option? :-)
> > >
> > > Yes, we do :-)
> >
> > It's not listed in lang.opt, which is where I checked for
> > an option.  Should it be listed in lang.opt?
> 
> No. It's in gcc/common.opt.
> 

Okay.

But, it does work correctly.

program a
   implicit none
   integer n
   real, allocatable :: b(:)
   n = 5
   allocate(b(n))
   call fill(b,n)
   print *, b
end program a

subroutine fill(x,m)
   implicit none
   integer, intent(in) :: m
   real, intent(out) :: x(*)
   integer i
   do i = 1, m
      x(i) = real(i)
   end do
end subroutine fill

dhcp-78-96:kargl[224] /home/sgk/bin/gfortran -static -o a -fbounds-check a.f90
dhcp-78-96:kargl[225] ./a
Fortran runtime error: Array reference out of bounds

If I look at the -fdump-tree-original, i find


    T.5 = b.dim[0].lbound;
    {
      int8 T.6;

      T.6 = b.dim[0].ubound - T.5;
      if (__builtin_expect (b.dim[0].lbound > T.5, 0))
        {
          _gfortran_runtime_error ("Array bound mismatch", "a.f90", 8);
        }

which can't be right.
  



-- 
Steve


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