diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2018-01-22 15:31:08 +0200 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2018-01-22 15:31:08 +0200 |
commit | 6b271a2ec41ac5eb9331a7c5857e3719c9a24ef4 (patch) | |
tree | f3d3d61b5081f8526d7ce8cd08c24e54cd76f230 /gcc/fortran/array.c | |
parent | 1dba94d42c835094c540e6cbeeaaa3c2e068a624 (diff) | |
download | gcc-6b271a2ec41ac5eb9331a7c5857e3719c9a24ef4.zip gcc-6b271a2ec41ac5eb9331a7c5857e3719c9a24ef4.tar.gz gcc-6b271a2ec41ac5eb9331a7c5857e3719c9a24ef4.tar.bz2 |
PR 78534, 83704 Large character lengths
This patch fixes various parts of the code to use a larger type than
int for the character length. Depending on the situation,
HOST_WIDE_INT, size_t, or gfc_charlen_t is appropriate.
Regtested on x86_64-pc-linux-gnu and i686-pc-linux-gnu.
gcc/fortran/ChangeLog:
2018-01-22 Janne Blomqvist <jb@gcc.gnu.org>
PR 78534
PR 83704
* arith.c (gfc_arith_concat): Use size_t for string length.
(gfc_compare_string): Likewise.
(gfc_compare_with_Cstring): Likewise.
* array.c (gfc_resolve_character_array_constructor): Use
HOST_WIDE_INT, gfc_mpz_get_hwi.
* check.c (gfc_check_fe_runtime_error): Use size_t.
* data.c (create_character_initializer): Use HOST_WIDE_INT,
gfc_extract_hwi.
* decl.c (gfc_set_constant_character_len): Use gfc_charlen_t.
(add_init_expr_to_sym): Use HOST_WIDE_INT.
* expr.c (gfc_build_init_expr): Use HOST_WIDE_INT,
gfc_extract_hwi.
(gfc_apply_init): Likewise.
* match.h (gfc_set_constant_character_len): Update prototype.
* primary.c (match_string_constant): Use size_t.
* resolve.c (resolve_ordinary_assign): Use HOST_WIDE_INT,
gfc_mpz_get_hwi.
* simplify.c (init_result_expr): Likewise.
(gfc_simplify_len_trim): Use size_t.
* target-memory.c (gfc_encode_character): Use size_t.
(gfc_target_encode_expr): Use HOST_WIDE_INT, gfc_mpz_get_hwi.
(interpret_array): Use size_t.
(gfc_interpret_character): Likewise.
* target-memory.h (gfc_encode_character): Update prototype.
(gfc_interpret_character): Likewise.
(gfc_target_interpret_expr): Likewise.
* trans-const.c (gfc_build_string_const): Use size_t for length
argument.
(gfc_build_wide_string_const): Likewise.
* trans-const.h (gfc_build_string_const): Likewise.
(gfc_build_wide_string_const): Likewise.
2018-01-22 Janne Blomqvist <jb@gcc.gnu.org>
PR 78534
PR 83704
* gfortran.dg/string_1.f90: Remove printing the length.
From-SVN: r256944
Diffstat (limited to 'gcc/fortran/array.c')
-rw-r--r-- | gcc/fortran/array.c | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index 882fe57..93deb0d 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -1962,7 +1962,7 @@ bool gfc_resolve_character_array_constructor (gfc_expr *expr) { gfc_constructor *p; - int found_length; + HOST_WIDE_INT found_length; gcc_assert (expr->expr_type == EXPR_ARRAY); gcc_assert (expr->ts.type == BT_CHARACTER); @@ -1994,7 +1994,7 @@ got_charlen: for (p = gfc_constructor_first (expr->value.constructor); p; p = gfc_constructor_next (p)) { - int current_length = -1; + HOST_WIDE_INT current_length = -1; gfc_ref *ref; for (ref = p->expr->ref; ref; ref = ref->next) if (ref->type == REF_SUBSTRING @@ -2005,19 +2005,11 @@ got_charlen: if (p->expr->expr_type == EXPR_CONSTANT) current_length = p->expr->value.character.length; else if (ref) - { - long j; - j = mpz_get_ui (ref->u.ss.end->value.integer) - - mpz_get_ui (ref->u.ss.start->value.integer) + 1; - current_length = (int) j; - } + current_length = gfc_mpz_get_hwi (ref->u.ss.end->value.integer) + - gfc_mpz_get_hwi (ref->u.ss.start->value.integer) + 1; else if (p->expr->ts.u.cl && p->expr->ts.u.cl->length && p->expr->ts.u.cl->length->expr_type == EXPR_CONSTANT) - { - long j; - j = mpz_get_si (p->expr->ts.u.cl->length->value.integer); - current_length = (int) j; - } + current_length = gfc_mpz_get_hwi (p->expr->ts.u.cl->length->value.integer); else return true; @@ -2027,9 +2019,9 @@ got_charlen: found_length = current_length; else if (found_length != current_length) { - gfc_error ("Different CHARACTER lengths (%d/%d) in array" - " constructor at %L", found_length, current_length, - &p->expr->where); + gfc_error ("Different CHARACTER lengths (%ld/%ld) in array" + " constructor at %L", (long) found_length, + (long) current_length, &p->expr->where); return false; } @@ -2051,7 +2043,7 @@ got_charlen: /* If we've got a constant character length, pad according to this. gfc_extract_int does check for BT_INTEGER and EXPR_CONSTANT and sets max_length only if they pass. */ - gfc_extract_int (expr->ts.u.cl->length, &found_length); + gfc_extract_hwi (expr->ts.u.cl->length, &found_length); /* Now pad/truncate the elements accordingly to the specified character length. This is ok inside this conditional, as in the case above @@ -2063,13 +2055,13 @@ got_charlen: if (p->expr->expr_type == EXPR_CONSTANT) { gfc_expr *cl = NULL; - int current_length = -1; + HOST_WIDE_INT current_length = -1; bool has_ts; if (p->expr->ts.u.cl && p->expr->ts.u.cl->length) { cl = p->expr->ts.u.cl->length; - gfc_extract_int (cl, ¤t_length); + gfc_extract_hwi (cl, ¤t_length); } /* If gfc_extract_int above set current_length, we implicitly |