[Patch, Fortran] PR33745 - fix bound checking at run time (wrong code) and compile time (missing diagnostic)

Tobias Burnus burnus@net-b.de
Sat Oct 13 17:29:00 GMT 2007


:ADDPATCH fortran:

Run time:
For assumed-size arrays, the upper limit of the last dimension cannot be
checked as it is unknown. trans-arrays.c's gfc_conv_ss_startstride
contained a check, however, the loop "for (n = 0; n < loop->dimen; n++)"
only checks for ranges and not for elements/vectors. Thus for "j(1,1:2)"
only the second dimension is checked. The variables are then n=0,
loop->dimen=1, however, n=0 denotes the second dimension ("1") and the
maximal dimension is info->ref->u.ar.dimen = 2. Therefore the check
   n == info->ref->u.ar.dimen - 1  /* 0 == (2 - 1) */
was false and the upper bound of the second dimension (= assumed size)
was checked (-> bogus run-time error).  The solution is to use the
absolute dimension "dim" ("dim = info->dim[n]").

Compile time:
Here, the problem is similar. Assume that jp's is defined as "jp(2,*)"
then "jp(3,1:2)" is out of bounds in the first dimension; however,
gfortran did not detect it. In resolve.c's "check_dimension(int i,
....)" (here, "i" is the dimension index) there is a "switch
(ar->type)". ar-type contains the overall type (which is AR_SECTION for
"jp(3,1:2)"); actually, the needed information is the type for the
current dimension, i.e. ar->dimen_type[i].
I fixed that and took also the opportunity to improve the diagnostic output.

Build and regression tested on x86-64/Linux. OK for the trunk?

Tobias
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: bounds-check.diff
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20071013/a01e71cd/attachment.ksh>


More information about the Fortran mailing list