re PR fortran/34945 (LBOUND fails for array with KIND(complex) used in zero-sized...
authorPaul Thomas <pault@gcc.gnu.org>
Tue, 5 Feb 2008 13:33:35 +0000 (13:33 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Tue, 5 Feb 2008 13:33:35 +0000 (13:33 +0000)
2008-02-05  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/34945
* array.c (match_array_element_spec): Remove check for negative
array size.
(gfc_resolve_array_spec): Add check for negative size.

2008-02-05  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/34945
* gfortran.dg/bounds_check_13.f: New test.

From-SVN: r132121

gcc/fortran/ChangeLog
gcc/fortran/array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/bounds_check_13.f [new file with mode: 0644]

index 97a1a179f2d5a92f2616c6d0e5821d9ec6393f04..b795f897848b5ee51c1a69de67372b54ff14143b 100644 (file)
@@ -1,3 +1,10 @@
+2008-02-05  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/34945
+       * array.c (match_array_element_spec): Remove check for negative
+       array size.
+       (gfc_resolve_array_spec): Add check for negative size.
+
 2008-02-05  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/32315
index 0c30b3374cc582a264b1c44f3e913f2b8870677e..75f80edc3b53658f78be3d1d91bd7581181c8216 100644 (file)
@@ -250,6 +250,21 @@ gfc_resolve_array_spec (gfc_array_spec *as, int check_constant)
       e = as->upper[i];
       if (resolve_array_bound (e, check_constant) == FAILURE)
        return FAILURE;
+
+      if ((as->lower[i] == NULL) || (as->upper[i] == NULL))
+       continue;
+
+      /* If the size is negative in this dimension, set it to zero.  */
+      if (as->lower[i]->expr_type == EXPR_CONSTANT
+           && as->upper[i]->expr_type == EXPR_CONSTANT
+           && mpz_cmp (as->upper[i]->value.integer,
+                       as->lower[i]->value.integer) < 0)
+       {
+         gfc_free_expr (as->upper[i]);
+         as->upper[i] = gfc_copy_expr (as->lower[i]);
+         mpz_sub_ui (as->upper[i]->value.integer,
+                     as->upper[i]->value.integer, 1);
+       }
     }
 
   return SUCCESS;
@@ -318,15 +333,6 @@ match_array_element_spec (gfc_array_spec *as)
   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 d51c3ed37ab6b41e8757f2a90e242e7588d19efd..daf3f078010a5e0c81f74107ec9dfe37d9eb6bee 100644 (file)
@@ -1,3 +1,8 @@
+2008-02-05  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/34945
+       * gfortran.dg/bounds_check_13.f: New test.
+
 2008-02-05  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        PR testsuite/33946
diff --git a/gcc/testsuite/gfortran.dg/bounds_check_13.f b/gcc/testsuite/gfortran.dg/bounds_check_13.f
new file mode 100644 (file)
index 0000000..3581a18
--- /dev/null
@@ -0,0 +1,21 @@
+! { dg-do compile }
+! Tests the fix for PR34945, in which the lbound = KIND(YDA) was not resolved
+! in time to set the size of TEST_ARRAY to zero.
+!
+! Contributed by Dick Hendrickson <dick.hendrickson@gmail.com>
+!
+      SUBROUTINE VF0009(IDA1,IDA2,YDA,HDA)
+      INTEGER(4) IDA1(4)
+      INTEGER(4) IDA2(4)
+      COMPLEX(8) YDA(2)
+      INTEGER(4) HDA(3)
+!  I N I T I A L I Z A T I O N  S E C T I O N
+      COMPLEX(KIND=4) :: TEST_ARRAY
+     $(  4:5,
+     $   KIND(YDA):5,
+     $   4:5,
+     $   4:5  )
+!  T E S T  S T A T E M E N T S
+       IDA1(1:4) = LBOUND(TEST_ARRAY)
+      END SUBROUTINE
+