re PR fortran/85603 (ICE with character array substring assignment)
authorPaul Thomas <pault@gcc.gnu.org>
Sat, 22 Sep 2018 10:21:25 +0000 (10:21 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sat, 22 Sep 2018 10:21:25 +0000 (10:21 +0000)
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.

From-SVN: r264502

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

index e6bf429494810861b8b9bbc30efe938bef1e7a30..14a1de1da9384f74ed71f5d0924fb7d8c5ea5f88 100644 (file)
@@ -1,3 +1,9 @@
+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-21  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/77325
index 9e00eb0474faf4838d64b9d671df262aa3c12539..0d699edba93cde5757446e88cf5af93aa98cf540 100644 (file)
@@ -9950,7 +9950,8 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo *loop,
     {
       if (expr2->ts.deferred)
        {
-         if (VAR_P (expr2->ts.u.cl->backend_decl))
+         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 7cba59c834706eaeaad860ab0284c0cdf7069beb..78800e898c949699aa930b1b331b7e1c18bb37dd 100644 (file)
@@ -1,3 +1,8 @@
+2018-09-22  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/85603
+       * gfortran.dg/deferred_character_23.f90 : New test.
+
 2018-09-21  Jeff Law  <law@redhat.com>
 
        * gcc.dg/tree-ssa/vrp113.c: Disable EVRP.
diff --git a/gcc/testsuite/gfortran.dg/deferred_character_23.f90 b/gcc/testsuite/gfortran.dg/deferred_character_23.f90
new file mode 100644 (file)
index 0000000..c018334
--- /dev/null
@@ -0,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