This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patc, fortran] PR85603 - ICE with character array substring assignment
- From: Paul Richard Thomas <paul dot richard dot thomas at gmail dot com>
- To: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 22 Sep 2018 11:23:46 +0100
- Subject: [Patc, fortran] PR85603 - ICE with character array substring assignment
Yet another 'obvious' deferred character fix. Committed to trunk as
r264502. Will backport in about ten days time.
Paul
2018-09-22 Paul Thomas <pault@gcc.gnu.org>
PR fortran/85603
* trans-array.c (gfc_alloc_allocatable_for_assignment): Test
the charlen backend_decl before using the VAR_P macro.
2018-09-22 Paul Thomas <pault@gcc.gnu.org>
PR fortran/85603
* gfortran.dg/deferred_character_23.f90 : New test.
Index: gcc/fortran/trans-array.c
===================================================================
*** gcc/fortran/trans-array.c (revision 264486)
--- gcc/fortran/trans-array.c (working copy)
*************** gfc_alloc_allocatable_for_assignment (gf
*** 9950,9956 ****
{
if (expr2->ts.deferred)
{
! if (VAR_P (expr2->ts.u.cl->backend_decl))
tmp = expr2->ts.u.cl->backend_decl;
else
tmp = rss->info->string_length;
--- 9950,9957 ----
{
if (expr2->ts.deferred)
{
! if (expr2->ts.u.cl->backend_decl
! && VAR_P (expr2->ts.u.cl->backend_decl))
tmp = expr2->ts.u.cl->backend_decl;
else
tmp = rss->info->string_length;
Index: gcc/testsuite/gfortran.dg/deferred_character_23.f90
===================================================================
*** gcc/testsuite/gfortran.dg/deferred_character_23.f90 (nonexistent)
--- gcc/testsuite/gfortran.dg/deferred_character_23.f90 (working copy)
***************
*** 0 ****
--- 1,22 ----
+ ! { dg-do run }
+ !
+ ! Tests the fix for PR85603.
+ !
+ ! Contributed by Walt Spector <w6ws@earthlink.net>
+ !
+ program strlen_bug
+ implicit none
+
+ character(:), allocatable :: strings(:)
+ integer :: maxlen
+
+ strings = [ character(32) :: &
+ 'short', &
+ 'somewhat longer' ]
+ maxlen = maxval (len_trim (strings))
+ if (maxlen .ne. 15) stop 1
+ strings = strings(:)(:maxlen) ! Used to ICE
+ if (any (strings .ne. ['short ','somewhat longer'])) stop 2
+
+ deallocate (strings) ! To check for memory leaks
+ end program