re PR fortran/84065 (string_1.f90 fails since r256944)
authorJakub Jelinek <jakub@gcc.gnu.org>
Sat, 27 Jan 2018 10:28:20 +0000 (11:28 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 27 Jan 2018 10:28:20 +0000 (11:28 +0100)
PR fortran/84065
* decl.c (add_init_expr_to_sym): Ignore initializers for too large
lengths.

From-SVN: r257121

gcc/fortran/ChangeLog
gcc/fortran/decl.c

index 9a2cc320991d84f9737eccf16196f25f7686c687..8660530c07388a09d8f6f0b2d3a0f73667888988 100644 (file)
@@ -1,6 +1,12 @@
+2018-01-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/84065
+       * decl.c (add_init_expr_to_sym): Ignore initializers for too large
+       lengths.
+
 2018-01-26  Damian Rouson  <damian@sourceryinstitute.org>
-       Alessandro Fanfarillo  <fanfarillo.gcc@gmail.com>
-       Soren Rasmussen  <s.c.rasmussen@gmail.com>
+           Alessandro Fanfarillo  <fanfarillo.gcc@gmail.com>
+           Soren Rasmussen  <s.c.rasmussen@gmail.com>
 
        Partial support for Fortran 2018 teams features.
 
index 7922eefbd631f30f6912e7676f017842fd13d46a..307caa215d68a754fdd4dc1d58362161721328b5 100644 (file)
@@ -1757,22 +1757,32 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
              if (!gfc_specification_expr (sym->ts.u.cl->length))
                return false;
 
-             HOST_WIDE_INT len = gfc_mpz_get_hwi (sym->ts.u.cl->length->value.integer);
-
-             if (init->expr_type == EXPR_CONSTANT)
-               gfc_set_constant_character_len (len, init, -1);
-             else if (init->expr_type == EXPR_ARRAY)
+             int k = gfc_validate_kind (BT_INTEGER, gfc_charlen_int_kind,
+                                        false);
+             /* resolve_charlen will complain later on if the length
+                is too large.  Just skeep the initialization in that case.  */
+             if (mpz_cmp (sym->ts.u.cl->length->value.integer,
+                          gfc_integer_kinds[k].huge) <= 0)
                {
-                 gfc_constructor *c;
+                 HOST_WIDE_INT len
+                   = gfc_mpz_get_hwi (sym->ts.u.cl->length->value.integer);
+
+                 if (init->expr_type == EXPR_CONSTANT)
+                   gfc_set_constant_character_len (len, init, -1);
+                 else if (init->expr_type == EXPR_ARRAY)
+                   {
+                     gfc_constructor *c;
 
-                 /* Build a new charlen to prevent simplification from
-                    deleting the length before it is resolved.  */
-                 init->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
-                 init->ts.u.cl->length = gfc_copy_expr (sym->ts.u.cl->length);
+                     /* Build a new charlen to prevent simplification from
+                        deleting the length before it is resolved.  */
+                     init->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
+                     init->ts.u.cl->length
+                       = gfc_copy_expr (sym->ts.u.cl->length);
 
-                 for (c = gfc_constructor_first (init->value.constructor);
-                      c; c = gfc_constructor_next (c))
-                   gfc_set_constant_character_len (len, c->expr, -1);
+                     for (c = gfc_constructor_first (init->value.constructor);
+                          c; c = gfc_constructor_next (c))
+                       gfc_set_constant_character_len (len, c->expr, -1);
+                   }
                }
            }
        }