aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/expr.c
diff options
context:
space:
mode:
authorJanne Blomqvist <jb@gcc.gnu.org>2018-01-22 15:31:08 +0200
committerJanne Blomqvist <jb@gcc.gnu.org>2018-01-22 15:31:08 +0200
commit6b271a2ec41ac5eb9331a7c5857e3719c9a24ef4 (patch)
treef3d3d61b5081f8526d7ce8cd08c24e54cd76f230 /gcc/fortran/expr.c
parent1dba94d42c835094c540e6cbeeaaa3c2e068a624 (diff)
downloadgcc-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/expr.c')
-rw-r--r--gcc/fortran/expr.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 936b6b6..2a5f8ec 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -4088,9 +4088,7 @@ gfc_build_default_init_expr (gfc_typespec *ts, locus *where)
gfc_expr *
gfc_build_init_expr (gfc_typespec *ts, locus *where, bool force)
{
- int char_len;
gfc_expr *init_expr;
- int i;
/* Try to build an initializer expression. */
init_expr = gfc_get_constant_expr (ts->type, ts->kind, where);
@@ -4202,10 +4200,10 @@ gfc_build_init_expr (gfc_typespec *ts, locus *where, bool force)
&& ts->u.cl->length
&& ts->u.cl->length->expr_type == EXPR_CONSTANT)
{
- char_len = mpz_get_si (ts->u.cl->length->value.integer);
+ HOST_WIDE_INT char_len = gfc_mpz_get_hwi (ts->u.cl->length->value.integer);
init_expr->value.character.length = char_len;
init_expr->value.character.string = gfc_get_wide_string (char_len+1);
- for (i = 0; i < char_len; i++)
+ for (size_t i = 0; i < (size_t) char_len; i++)
init_expr->value.character.string[i]
= (unsigned char) gfc_option.flag_init_character_value;
}
@@ -4255,13 +4253,11 @@ gfc_apply_init (gfc_typespec *ts, symbol_attribute *attr, gfc_expr *init)
&& ts->u.cl
&& ts->u.cl->length && ts->u.cl->length->expr_type == EXPR_CONSTANT)
{
- int len;
-
gcc_assert (ts->u.cl && ts->u.cl->length);
gcc_assert (ts->u.cl->length->expr_type == EXPR_CONSTANT);
gcc_assert (ts->u.cl->length->ts.type == BT_INTEGER);
- len = mpz_get_si (ts->u.cl->length->value.integer);
+ HOST_WIDE_INT len = gfc_mpz_get_hwi (ts->u.cl->length->value.integer);
if (init->expr_type == EXPR_CONSTANT)
gfc_set_constant_character_len (len, init, -1);
@@ -4276,7 +4272,6 @@ gfc_apply_init (gfc_typespec *ts, symbol_attribute *attr, gfc_expr *init)
if (ctor)
{
- int first_len;
bool has_ts = (init->ts.u.cl
&& init->ts.u.cl->length_from_typespec);
@@ -4285,7 +4280,7 @@ gfc_apply_init (gfc_typespec *ts, symbol_attribute *attr, gfc_expr *init)
length. This need not be the length of the LHS! */
gcc_assert (ctor->expr->expr_type == EXPR_CONSTANT);
gcc_assert (ctor->expr->ts.type == BT_CHARACTER);
- first_len = ctor->expr->value.character.length;
+ gfc_charlen_t first_len = ctor->expr->value.character.length;
for ( ; ctor; ctor = gfc_constructor_next (ctor))
if (ctor->expr->expr_type == EXPR_CONSTANT)