This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR fortran/91716
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>
- Cc: Jeff Law <law at redhat dot com>
- Date: Fri, 13 Sep 2019 10:07:05 +0000
- Subject: [PATCH] Fix PR fortran/91716
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v7v/SwKUUeZQmqxNVHxDbjS19VqUvc8fDuhz8Z4MGBU=; b=SK77otGWsuCnnKL6B3to2wdrEnx8TfXoV7H7V+z7FzRciKikmsRUo14K4KChWX7lLW/ABUfxPaFieTtZMMQQrFIto7WyF0uA4H9ptjKAi2B6weWnMt5prS6RkQCqj9Odwb6NySfEVxjhPEriFHrKlmlvkw6bx5es3q4sqVoCve2cEE5pXsL9qT+eOmQ+CYoQxJWAkRNEnXWpZQyzveTPhTqyPaZmhjULvmdfKytuavl9KkxhKvbKbd/dEqtQEcrSakRUzun2TDigIDLEgoePg1qdoQFGkZGsssPtRdNLRrFXdA8VlolAD3TLf6YuKchMRw4Urtw7ecok5fmAlhB8DQ==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gu11wgcVao0hLVaTFrlBJDYmZ8wv/QFg3ZW4my3g3i77ioZ5QR83PAxxy5mZPwux6h+KZ34xb+dE7SPuky/lIn/UTXnRDtLOUr2jL+z+UewjBSTFBctiVZstHF7IkL1wbGv3mfIzzicawWYRf5rnaBqIVYBKdRdTWW62yHmyoiOiIhTx7f7P9+ie63ymc/SehoSWm5gCmmPuBl2k6JBxsVh1lMPIysnZXvaKEK19TE260Rqu9gwEj73zJGCxcTsK0/enoFPLUPIWyZa5kfnN5G0WTIuzhtM2OFgREbphglrtXDUMedDsF0nJiK6z2HmLSVldlPHL+xLvoYeJIbiWfw==
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.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.
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