This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch, Fortran] PR 58146, enable array slice compile-time bounds checking
- From: Mikael Morin <mikael dot morin at sfr dot fr>
- To: Thomas Koenig <tkoenig at netcologne dot de>
- Cc: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 22 Aug 2013 23:30:01 +0200
- Subject: Re: [patch, Fortran] PR 58146, enable array slice compile-time bounds checking
- References: <520BFABE dot 8040603 at netcologne dot de>
Le 14/08/2013 23:46, Thomas Koenig a écrit :
> Hello world,
>
> the attached patch enables more sophisticated bounds-checking on
> array slices by using gfc_dep_difference to calculate extents.
> The information may also be useful in other places of the
> front end, I don't really know.
>
> There is one wrinkle (alluded to in the comments) which makes
> this harder. When somebody changes the value of a variable
> used in detemining the size of an array, such as
>
> subroutine foo(a,n)
> real, dimension(n) :: a
>
> n = n -2
>
> print *,ubound(a(n-1:))
>
> we cannot compare n-1 against n and think that their difference is
> one :-(
>
> This is why I restricted myself to expressions where all
> indices are specified, e.g. in a(n+1:n+4) or none are specified,
> as in a(:).
>
> In order for this to work on 64-bit systems, it was necessary
> to look through widening integer conversions, so I added that
> functionality to discard_nops. Using this function in
> gfc_dep_compare_expr made this function shorter and cleaner.
>
> Regression-tested. OK for trunk?
>
This looks mostly good. The dependency.c cleanup is nice, I have yet to
understand what the 'end == NULL' condition is for. I come back to you
soon.
Mikael