This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch,Fortran] Allow for zero-dimension explict-shaped arrays (PR30514)
- From: Tobias Burnus <burnus at net-b dot de>
- To: "'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: Sat, 03 Feb 2007 13:46:41 +0100
- Subject: [Patch,Fortran] Allow for zero-dimension explict-shaped arrays (PR30514)
:ADDPATCH fortran:
gfortran failed for:
integer(1) :: i(1:-1)
i = 5
and it ends up in an endless loop, as FX found out, for
integer :: i(2:0), j(1:0)
integer, parameter :: k(2:0) = 0, l(1:0) = 0
i = k
j = l
Note that those arrays are valid:
See 5.1.2.5.1 Explicit-shape array:
"If the upper bound is less than the lower bound, the range is empty, the
extent in that dimension is zero, and the array is of zero size."
Bootstapped and regression tested on x86_64-unknown-linux-gnu.
Ok for the trunk and the usual week+ later for 4.2?
(It also affects 4.1, do we want to fix it there too [after the 4.1.x
release]?)
Tobias
fortran/
2007-02-03 Paul Thomas <pault@gcc.gnu.org>
PR fortran/30514
* array.c (match_array_element_spec): Allow for zero-dimension
explicit-shape arrays.
testsuite/
2007-02-03 Tobias Burnus <burnus@net-b.de>
PR fortran/30514
gfortran.dg/array_3.f90: New zero-dimension array test.
Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c (Revision 121540)
+++ gcc/fortran/array.c (Arbeitskopie)
@@ -319,6 +319,15 @@
if (m == MATCH_NO)
return AS_ASSUMED_SHAPE;
+ /* If the size is negative in this dimension, set it to zero. */
+ if ((*lower)->expr_type == EXPR_CONSTANT
+ && (*upper)->expr_type == EXPR_CONSTANT
+ && mpz_cmp ((*upper)->value.integer, (*lower)->value.integer) < 0)
+ {
+ gfc_free_expr (*upper);
+ *upper = gfc_copy_expr (*lower);
+ mpz_sub_ui ((*upper)->value.integer, (*upper)->value.integer, 1);
+ }
return AS_EXPLICIT;
}
Index: gcc/testsuite/gfortran.dg/array_3.f90
===================================================================
--- gcc/testsuite/gfortran.dg/array_3.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/array_3.f90 (Revision 0)
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! The following arrays have zero dimensions; this is valid.
+! PR fortran/30514
+program test
+implicit none
+integer(1) :: z(1:-1)
+integer :: i(2:0), j(1:0)
+integer, parameter :: k(2:0) = 0, l(1:0) = 0
+z = 5
+i = k
+j = l
+end program test