[Bug fortran/50130] [4.6/4.7 Regression] ICE with invalid array slice

burnus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Aug 19 21:27:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50130

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-invalid-code
                 CC|                            |burnus at gcc dot gnu.org,
                   |                            |tkoenig at gcc dot gnu.org
   Target Milestone|---                         |4.6.2

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-08-19 21:19:50 UTC ---
Working: GCC 4.6-trunk 2010-07-16-r162255
Failing: GCC 4.6-trunk 2010-08-28-r163612

array.c's gfc_ref_dimen_size contains:

      mpz_div (*result, *result, stride);
      /* Zero stride caught earlier.  */

The comment is correct: The ICE comes already one line earlier ...

Seemingly caused by Rev. 163041:
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=163041
    2010-08-09  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/44235
        * array.c (gfc_ref_dimen_size):  Add end argument.
        If end is non-NULL, calculate it.
        (ref_size):  Adjust call to gfc_ref_dimen_size.
        (gfc_array_dimen_size):  Likewise.
        (gfc_array_res_shape):  Likewise.
        * gfortran.h:  Adjust prototype for gfc_ref_dimen_size.
        * resolve.c (resolve_array_ref):  For stride not equal to -1,
        fill in the lowest possible end.


The problem seems to be the following in resolve_array_ref:

      /* Fill in the upper bound, which may be lower than the
         specified one for something like a(2:10:5), which is
         identical to a(2:7:5).  Only relevant for strides not equal
         to one.  */
      [...]
          if (gfc_ref_dimen_size (ar, i, &size, &end) == SUCCESS)
[...]
  if (!ar->as->cray_pointee && compare_spec_to_ref (ar) == FAILURE)

In the call to gfc_ref_dimen_size one has the division by zero.

With the call to compare_spec_to_ref one reaches via check_dimension the
"Illegal stride of zero" check, which obviously comes too late.



More information about the Gcc-bugs mailing list