Please find attached a fix for PR53298.
This appears to be a very simple fix, however, since it involves
structures I'm unfamiliar with I think it needs checking.
When the gfc_ref structure is created for a (1:) substring it has an
expression for start and a NULL for the end. For (:5) the start
expression is NULL, a new expression structure is created and assigned
to start. If the end expression is missing a new expression structure
is not created, I would've expected an expression for the missing end
to be created but don't know how it should be populated.
When the gfc_ref structure is processed in gfc_walk_array_ref two gfc_ss
structures are created, one for the start expression and one for the end
expression. For (1:) the end expression is NULL and will lead to the
ICE. I added a check for the end expression being NULL and if so a
gfc_ss structure is not created for substring end. I did not expect the
change to work but it did.
The patch has been tested on x98_64 using make check-fortran.
If OK I can commit to master and backport.
Fortran : ICE in gfc_conv_scalarized_array_ref PR53298
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-20 Mark Eggleston <markeggles...@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-20 Mark Eggleston <markeggles...@gcc.gnu.org>
gcc/testsuite/
PR fortran/53298
* gfortran.dg/pr53298.f90: New test.
--
https://www.codethink.co.uk/privacy.html
>From aa1537ffa55d2c85c1f61df3301182627ca35ca3 Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggles...@gcc.gnu.org>
Date: Fri, 17 Jul 2020 14:22:48 +0100
Subject: [PATCH] Fortran : ICE in gfc_conv_scalarized_array_ref PR53298
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-20 Mark Eggleston <markeggles...@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-20 Mark Eggleston <markeggles...@gcc.gnu.org>
gcc/testsuite/
PR fortran/53298
* gfortran.dg/pr53298.f90: New test.
---
gcc/fortran/trans-array.c | 3 ++-
gcc/testsuite/gfortran.dg/pr53298.f90 | 14 ++++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gfortran.dg/pr53298.f90
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 54e1107c711..8f93b43bafb 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -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
index 00000000000..998f88df926
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr53298.f90
@@ -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" }
--
2.11.0