Hi,
this fixes a test case where a short string constant is put in a larger memory
object.
The consistency check in varasm.c is failed because both types should agree.
Since the failed assertion is just a gcc_checking_assert I think a back-port of
this fix
to the gcc-9 branch will not be necessary.
Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?
Thanks
Bernd.
2019-09-13 Bernd Edlinger <bernd.edlin...@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.edlin...@hotmail.de>
PR fortran/91716
* gfortran.dg/pr91716.f90: New test.
Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c (revision 275685)
+++ gcc/fortran/trans-array.c (working copy)
@@ -6108,9 +6108,12 @@ gfc_conv_array_initializer (tree type, gfc_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));
@@ -6117,8 +6120,8 @@ gfc_conv_array_initializer (tree type, gfc_expr *
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: gcc/testsuite/gfortran.dg/pr91716.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr91716.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/pr91716.f90 (working copy)
@@ -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