re PR fortran/91716 (ICE in output_constant, at varasm.c:5026)
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Fri, 13 Sep 2019 11:33:18 +0000 (11:33 +0000)
committerBernd Edlinger <edlinger@gcc.gnu.org>
Fri, 13 Sep 2019 11:33:18 +0000 (11:33 +0000)
2019-09-13  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        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  <bernd.edlinger@hotmail.de>

        PR fortran/91716
        * gfortran.dg/pr91716.f90: New test.

From-SVN: r275698

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr91716.f90 [new file with mode: 0644]

index bf721c7d43e832d22852a64d67899f454c3e764c..a396418118d24bdcb8325278b3aa3c271420d499 100644 (file)
@@ -1,3 +1,9 @@
+2019-09-13  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       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  <pault@gcc.gnu.org>
 
        PR fortran/91717
index da7030192f5472250862c33b600e7ff55df9fc9d..8881fd953ed466000107f953302c658158e729bf 100644 (file)
@@ -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;
 
index ab1d7bc9312fc719b78d1e3844ce22d1a94d46d3..62766c215566101078cd362546ecffab57bbb360 100644 (file)
@@ -1,3 +1,8 @@
+2019-09-13  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       PR fortran/91716
+       * gfortran.dg/pr91716.f90: New test.
+
 2019-09-13  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/91717
diff --git a/gcc/testsuite/gfortran.dg/pr91716.f90 b/gcc/testsuite/gfortran.dg/pr91716.f90
new file mode 100644 (file)
index 0000000..d5de358
--- /dev/null
@@ -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