[patch, fortran] Warn about out-of-bounds access with DO subscripts

Thomas Koenig tkoenig@netcologne.de
Sat Sep 23 12:33:00 GMT 2017


Hello world,

here is an update and a ping for my patch at

https://gcc.gnu.org/ml/gcc-patches/2017-09/msg01104.html

This patch warns unconditionally for

   REAL A(3)
   DO I=1,4
      A(I) = 42.
   END DO

while only warning conditionally, dependent on a new flag,
for when the statement containing the expression is hidden
behind some IF or SELECT CASE statement or if there
is something in the DO loop which could potentially exit the loop,
so

   REAL A(3)
   DO I=1,4
     IF (CONDITON) A(I) = 42.
   END DO

will require the new -Wdo-subscript or the -Wextra flag.

Regression-tested. OK for trunk?

Regards

	Thomas

2017-09-23  Thomas Koenig  <tkoenig@gcc.gnu.org>

         * lang.opt:  Add -Wdo-subscript.
         * frontend-passes.c (do_t): New type.
         (doloop_list): Use variable of do_type.
         (if_level): Variable to track if levels.
         (select_level): Variable to track select levels.
         (gfc_run_passes): Initialize i_level and select_level.
         (doloop_code): Record current level of if + select
         level in doloop_list.  Add seen_goto if there could
         be a branch outside the loop. Use different type for
         doloop_list.
         (doloop_function): Call do_intent and do_subscript; move
         functionality of checking INTENT to do_intent.
         (insert_index_t): New type, for callback_insert_index.
         (callback_insert_index): New function.
         (insert_index): New function.
         (do_subscript): New function.
         (do_intent): New function.
         (gfc_code_walker): Keep track of if_level and select_level.
         * invoke.texi: Document -Wdo-subscript.

2017-09-23  Thomas Koenig  <tkoenig@gcc.gnu.org>

         * gfortran.dg/do_subscript_1.f90: New test.
         * gfortran.dg/do_subscript_2.f90: New test.
         * gfortran.dg/gomp/associate1.f90: Add out of bounds warning.
         * gfortran.dg/predcom-1.f: Adjust loop bounds.
         * gfortran.dg/unconstrained_commons.f: Add out of bounds warning.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p16.diff
Type: text/x-patch
Size: 17519 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20170923/b7e7c704/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: do_subscript_1.f90
Type: text/x-fortran
Size: 1693 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20170923/b7e7c704/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: do_subscript_2.f90
Type: text/x-fortran
Size: 683 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20170923/b7e7c704/attachment-0002.bin>


More information about the Gcc-patches mailing list