Fortran : ICE in gfc_conv_scalarized_array_ref PR53298
authorMark Eggleston <markeggleston@gcc.gnu.org>
Fri, 17 Jul 2020 13:22:48 +0000 (14:22 +0100)
committerMark Eggleston <markeggleston@gcc.gnu.org>
Wed, 29 Jul 2020 10:16:38 +0000 (11:16 +0100)
When an array of characters is an argument to a subroutine and
is accessed using (:)(1:) an ICE occurs.  The upper bound of the
substring does not have an expression and such should not have
a Scalarization State structure added to the Scalarization State
chain.

2020-07-29  Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/fortran/

PR fortran/53298
* trans-array.c (gfc_walk_array_ref): If ref->ss.end is set
call gfc_get_scalar_ss.

2020-07-29  Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/testsuite/

PR fortran/53298
* gfortran.dg/pr53298.f90: New test.

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

index 54e1107c71193e12421d0a6731aa8164ef807a73..8f93b43bafbeac3618b2e2d7eceecfd90d82e027 100644 (file)
@@ -10800,7 +10800,8 @@ gfc_walk_array_ref (gfc_ss * ss, gfc_expr * expr, gfc_ref * ref)
       if (ref->type == REF_SUBSTRING)
        {
          ss = gfc_get_scalar_ss (ss, ref->u.ss.start);
-         ss = gfc_get_scalar_ss (ss, ref->u.ss.end);
+         if (ref->u.ss.end)
+           ss = gfc_get_scalar_ss (ss, ref->u.ss.end);
        }
 
       /* We're only interested in array sections from now on.  */
diff --git a/gcc/testsuite/gfortran.dg/pr53298.f90 b/gcc/testsuite/gfortran.dg/pr53298.f90
new file mode 100644 (file)
index 0000000..998f88d
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do run }
+
+program test
+  character(len=5) :: str(3)
+  str = ["abcde", "12345", "ABCDE" ]
+  call f(str(:))
+contains
+  subroutine f(x)
+    character(len=*) :: x(:)
+    write(*,*) x(:)(1:) 
+  end subroutine f
+end program test
+
+! { dg-output "abcde12345ABCDE" }