From: law Date: Thu, 13 Sep 2018 18:42:16 +0000 (+0000) Subject: * trans-array.c (gfc_conv_array_initializer): Remove excess precision X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9957ead7c31a71520cc1e8b3dd104bbe0594fd6b;p=thirdparty%2Fgcc.git * trans-array.c (gfc_conv_array_initializer): Remove excess precision from overlength string initializers. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@264285 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 6249996ccbc3..becc184828c4 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2018-09-13 Bernd Edlinger + + * trans-array.c (gfc_conv_array_initializer): Remove excess precision + from overlength string initializers. + 2018-09-12 Paul Thomas PR fortran/87284 diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index adb2c0575a86..473bfc5419b6 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -5956,6 +5956,26 @@ gfc_conv_array_initializer (tree type, gfc_expr * expr) { case EXPR_CONSTANT: gfc_conv_constant (&se, c->expr); + + /* See gfortran.dg/charlen_15.f90 for instance. */ + if (TREE_CODE (se.expr) == STRING_CST + && TREE_CODE (type) == ARRAY_TYPE) + { + tree atype = type; + while (TREE_CODE (TREE_TYPE (atype)) == ARRAY_TYPE) + atype = TREE_TYPE (atype); + if (TREE_CODE (TREE_TYPE (atype)) == INTEGER_TYPE + && tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (se.expr))) + > tree_to_uhwi (TYPE_SIZE_UNIT (atype))) + { + unsigned HOST_WIDE_INT size + = tree_to_uhwi (TYPE_SIZE_UNIT (atype)); + const char *p = TREE_STRING_POINTER (se.expr); + + se.expr = build_string (size, p); + TREE_TYPE (se.expr) = atype; + } + } break; case EXPR_STRUCTURE: