From 85c2c761f44b23df217e20354bf83bbe5a4632dd Mon Sep 17 00:00:00 2001 From: Janne Blomqvist Date: Wed, 10 Jan 2018 13:18:31 +0200 Subject: [PATCH] PR 84740 Wrong string length type in bounds check Need to convert the RHS to the type of the LHS when assigning. Regtested on x86_64-pc-linux-gnu, committed as obvious. gcc/fortran/ChangeLog: 2018-01-10 Janne Blomqvist PR fortran/84740 * trans-array.c (gfc_trans_array_ctor_element): Convert RHS to the LHS type when assigning. From-SVN: r256425 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/trans-array.c | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index e19ed61698b..8ee13b1930f 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2018-01-10 Janne Blomqvist + + PR fortran/84740 + * trans-array.c (gfc_trans_array_ctor_element): Convert RHS to the + LHS type when assigning. + 2018-01-09 Steven G. Kargl PR fortran/83742 diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 474a7d1a84e..8a0afe9101c 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -1562,7 +1562,8 @@ gfc_trans_array_ctor_element (stmtblock_t * pblock, tree desc, if (first_len) { gfc_add_modify (&se->pre, first_len_val, - se->string_length); + fold_convert (TREE_TYPE (first_len_val), + se->string_length)); first_len = false; } else @@ -1571,7 +1572,9 @@ gfc_trans_array_ctor_element (stmtblock_t * pblock, tree desc, length. */ tree cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node, first_len_val, - se->string_length); + fold_convert (TREE_TYPE + (first_len_val), + se->string_length)); gfc_trans_runtime_check (true, false, cond, &se->pre, &expr->where, "Different CHARACTER lengths (%ld/%ld) in array constructor", -- 2.30.2