From: Jakub Jelinek Date: Sat, 27 Jan 2018 10:28:20 +0000 (+0100) Subject: re PR fortran/84065 (string_1.f90 fails since r256944) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=aeb8c0283e0509b9f95ace57ed5b64813725aec0;p=gcc.git re PR fortran/84065 (string_1.f90 fails since r256944) PR fortran/84065 * decl.c (add_init_expr_to_sym): Ignore initializers for too large lengths. From-SVN: r257121 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 9a2cc320991..8660530c073 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,6 +1,12 @@ +2018-01-27 Jakub Jelinek + + PR fortran/84065 + * decl.c (add_init_expr_to_sym): Ignore initializers for too large + lengths. + 2018-01-26 Damian Rouson - Alessandro Fanfarillo - Soren Rasmussen + Alessandro Fanfarillo + Soren Rasmussen Partial support for Fortran 2018 teams features. diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 7922eefbd63..307caa215d6 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -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); + } } } }