re PR fortran/84931 (Expansion of array constructor with constant implied-do-object...
authorThomas Koenig <tkoenig@gcc.gnu.org>
Mon, 19 Mar 2018 07:04:35 +0000 (07:04 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Mon, 19 Mar 2018 07:04:35 +0000 (07:04 +0000)
2018-03-19  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/84931
* simplify.c (gfc_convert_constant): Correctly handle iterators
for type conversion.

2018-03-19  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/84931
* gfortran.dg/array_constructor_52.f90: New test.

From-SVN: r258641

gcc/fortran/ChangeLog
gcc/fortran/simplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/array_constructor_52.f90 [new file with mode: 0644]

index 7b550aa75db313f179d0ad091f8286ac5be6e6a3..8db0754f4af837be598dcc344bc40a9ef38fa6b5 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-19  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/84931
+       * simplify.c (gfc_convert_constant): Correctly handle iterators
+       for type conversion.
+
 2018-03-18  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/77414
index 680e625c13056d71c979931ef7e42c27e6117351..44290ac2741c82ad187953075e7b426603c4f28b 100644 (file)
@@ -8016,26 +8016,32 @@ gfc_convert_constant (gfc_expr *e, bt type, int kind)
        {
          gfc_expr *tmp;
          if (c->iterator == NULL)
-           tmp = f (c->expr, kind);
+           {
+             tmp = f (c->expr, kind);
+             if (tmp == NULL)
+               {
+                 gfc_free_expr (result);
+                 return NULL;
+               }
+
+             gfc_constructor_append_expr (&result->value.constructor,
+                                          tmp, &c->where);
+           }
          else
            {
+             gfc_constructor *n;
              g = gfc_convert_constant (c->expr, type, kind);
-             if (g == &gfc_bad_expr)
+             if (g == NULL || g == &gfc_bad_expr)
                {
                  gfc_free_expr (result);
                  return g;
                }
-             tmp = g;
-           }
-
-         if (tmp == NULL)
-           {
-             gfc_free_expr (result);
-             return NULL;
+             n = gfc_constructor_get ();
+             n->expr = g;
+             n->iterator = gfc_copy_iterator (c->iterator);
+             n->where = c->where;
+             gfc_constructor_append (&result->value.constructor, n);
            }
-
-         gfc_constructor_append_expr (&result->value.constructor,
-                                      tmp, &c->where);
        }
 
       break;
index a7b96dda9661ec326fdf4e72f154fab974dfca9b..cdce63d00634aa5714af21b564fb1584de351a60 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-19  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/84931
+       * gfortran.dg/array_constructor_52.f90: New test.
+
 2018-03-17  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/77414
diff --git a/gcc/testsuite/gfortran.dg/array_constructor_52.f90 b/gcc/testsuite/gfortran.dg/array_constructor_52.f90
new file mode 100644 (file)
index 0000000..63581ac
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do  run }
+! PR 84931 - long array constructors with type conversion were not
+! handled correctly.
+program test
+   implicit none
+   integer, parameter :: n = 2**16
+   real, dimension(n) :: y
+   integer :: i
+   y = (/ (1, i=1, n) /)
+   if (y(2) /= 1) stop 1
+end program test