From 22cd031212e2376221435db5e9c6a298f24d7046 Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Fri, 13 Sep 2019 11:33:18 +0000 Subject: [PATCH] re PR fortran/91716 (ICE in output_constant, at varasm.c:5026) 2019-09-13 Bernd Edlinger PR fortran/91716 * trans-array.c (gfc_conv_array_initializer): Always assign the array type of the field to the string constant. testsuite: 2019-09-13 Bernd Edlinger PR fortran/91716 * gfortran.dg/pr91716.f90: New test. From-SVN: r275698 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/trans-array.c | 11 +++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr91716.f90 | 8 ++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr91716.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index bf721c7d43e..a396418118d 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-09-13 Bernd Edlinger + + PR fortran/91716 + * trans-array.c (gfc_conv_array_initializer): Always assign the + array type of the field to the string constant. + 2019-09-13 Paul Thomas PR fortran/91717 diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index da7030192f5..8881fd953ed 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -6108,17 +6108,20 @@ gfc_conv_array_initializer (tree type, gfc_expr * expr) 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))) + gcc_checking_assert (TREE_CODE (TREE_TYPE (atype)) + == INTEGER_TYPE); + gcc_checking_assert (TREE_TYPE (TREE_TYPE (se.expr)) + == TREE_TYPE (atype)); + if (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; } + TREE_TYPE (se.expr) = atype; } break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ab1d7bc9312..62766c21556 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-09-13 Bernd Edlinger + + PR fortran/91716 + * gfortran.dg/pr91716.f90: New test. + 2019-09-13 Paul Thomas PR fortran/91717 diff --git a/gcc/testsuite/gfortran.dg/pr91716.f90 b/gcc/testsuite/gfortran.dg/pr91716.f90 new file mode 100644 index 00000000000..d5de3588205 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr91716.f90 @@ -0,0 +1,8 @@ +! { dg-do compile } +! PR fortran/91716 +! Code contributed by Gerhard Steinmetz +module m + type t + character :: c(2) = [character(-1) :: 'a', 'b'] + end type +end -- 2.30.2