aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/data.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/data.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/data.c')
-rw-r--r--gcc/fortran/data.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/gcc/fortran/data.c b/gcc/fortran/data.c
index 6313f2e..fdd7052 100644
--- a/gcc/fortran/data.c
+++ b/gcc/fortran/data.c
@@ -104,11 +104,11 @@ static gfc_expr *
create_character_initializer (gfc_expr *init, gfc_typespec *ts,
gfc_ref *ref, gfc_expr *rvalue)
{
- int len, start, end, tlen;
+ HOST_WIDE_INT len, start, end, tlen;
gfc_char_t *dest;
bool alloced_init = false;
- gfc_extract_int (ts->u.cl->length, &len);
+ gfc_extract_hwi (ts->u.cl->length, &len);
if (init == NULL)
{
@@ -143,10 +143,10 @@ create_character_initializer (gfc_expr *init, gfc_typespec *ts,
return NULL;
}
- gfc_extract_int (start_expr, &start);
+ gfc_extract_hwi (start_expr, &start);
gfc_free_expr (start_expr);
start--;
- gfc_extract_int (end_expr, &end);
+ gfc_extract_hwi (end_expr, &end);
gfc_free_expr (end_expr);
}
else
@@ -174,16 +174,15 @@ create_character_initializer (gfc_expr *init, gfc_typespec *ts,
else
{
gfc_warning_now (0, "Initialization string at %L was truncated to "
- "fit the variable (%d/%d)", &rvalue->where,
- tlen, len);
+ "fit the variable (%ld/%ld)", &rvalue->where,
+ (long) tlen, (long) len);
len = tlen;
}
}
if (rvalue->ts.type == BT_HOLLERITH)
{
- int i;
- for (i = 0; i < len; i++)
+ for (size_t i = 0; i < (size_t) len; i++)
dest[start+i] = rvalue->representation.string[i];
}
else