re PR fortran/37469 (invalid GMP usage on gfortran.dg/parameter_array_init_3.f90)
authorMikael Morin <mikael.morin@tele2.fr>
Tue, 9 Dec 2008 19:20:18 +0000 (20:20 +0100)
committerMikael Morin <mikael@gcc.gnu.org>
Tue, 9 Dec 2008 19:20:18 +0000 (19:20 +0000)
2008-12-09  Mikael Morin  <mikael.morin@tele2.fr>

PR fortran/37469
* expr.c (find_array_element): Simplify array bounds.
Assert that both bounds are constant expressions.

From-SVN: r142606

gcc/fortran/ChangeLog
gcc/fortran/expr.c

index a46e79adeb1fc79cb956208297e6a7c05d8530c9..5c71e8f64e5521c5acd49bbcd1bdd6bcd5d43a7d 100644 (file)
@@ -1,3 +1,9 @@
+2008-12-09  Mikael Morin  <mikael.morin@tele2.fr>
+
+       PR fortran/37469
+       * expr.c (find_array_element): Simplify array bounds.
+       Assert that both bounds are constant expressions.
+
 2008-12-09  Mikael Morin  <mikael.morin@tele2.fr>
 
        PR fortran/35983
index 07dfc7a08a31fc953b8dfca9967274c4bfc38469..4bdee7c6a8c9230f6d5865459b6a7263f1e76ec3 100644 (file)
@@ -1028,6 +1028,14 @@ find_array_element (gfc_constructor *cons, gfc_array_ref *ar,
   mpz_init_set_ui (span, 1);
   for (i = 0; i < ar->dimen; i++)
     {
+      if (gfc_reduce_init_expr (ar->as->lower[i]) == FAILURE
+         || gfc_reduce_init_expr (ar->as->upper[i]) == FAILURE)
+       {
+         t = FAILURE;
+         cons = NULL;
+         goto depart;
+       }
+
       e = gfc_copy_expr (ar->start[i]);
       if (e->expr_type != EXPR_CONSTANT)
        {
@@ -1035,14 +1043,15 @@ find_array_element (gfc_constructor *cons, gfc_array_ref *ar,
          goto depart;
        }
 
+      gcc_assert (ar->as->upper[i]->expr_type == EXPR_CONSTANT
+                 && ar->as->lower[i]->expr_type == EXPR_CONSTANT);
+
       /* Check the bounds.  */
       if ((ar->as->upper[i]
-          && ar->as->upper[i]->expr_type == EXPR_CONSTANT
           && mpz_cmp (e->value.integer,
                       ar->as->upper[i]->value.integer) > 0)
-         || (ar->as->lower[i]->expr_type == EXPR_CONSTANT
-             && mpz_cmp (e->value.integer,
-                         ar->as->lower[i]->value.integer) < 0))
+         || (mpz_cmp (e->value.integer,
+                      ar->as->lower[i]->value.integer) < 0))
        {
          gfc_error ("Index in dimension %d is out of bounds "
                     "at %L", i + 1, &ar->c_where[i]);