[patch, Fortran] PR 58146, enable array slice compile-time bounds checking
Thomas Koenig
tkoenig@netcologne.de
Wed Aug 14 21:46:00 GMT 2013
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?
Thomas
2013-08-14 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/58146
* array.c (gfc_ref_dimen_size): If possible, use
gfc_dep_difference to calculate array refrence
sizes. Fall back to integer code otherwise.
* dependency.c (discard_nops). Move up.
Also discarde widening integer conversions.
(gfc_dep_compare_expr): Use discard_nops.
2013-08-14 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/58146
* gfortran.dg/bounds_check_18.f90: New test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p5.diff
Type: text/x-patch
Size: 5902 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20130814/01f5aaac/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bounds_check_18.f90
Type: text/x-fortran
Size: 231 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20130814/01f5aaac/attachment-0001.bin>
More information about the Fortran
mailing list