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: Sun, 25 Aug 2013 18:47:52 +0200
- Subject: Re: [patch, Fortran] PR 58146, enable array slice compile-time bounds checking
- References: <520BFABE dot 8040603 at netcologne dot de> <521682D9 dot 9020901 at sfr dot fr>
Le 22/08/2013 23:30, Mikael Morin a écrit :
> 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?
OK.
By the way, it seems that arg1 and arg2 declarations should be removed
in gfc_dep_compare_expr.
>>
> 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.
>
For what it's worth, 'end' is non-NULL in only one place and there the
gfc_ref_dimen_size result is discarded. Thus its handling should better
be inlined or have its own function separate from gfc_ref_dimen_size.
It seems to be a lot of trouble for little gain though.
Mikael