diff mbox series

Fortran : ICE in gfc_conv_scalarized_array_ref PR53298

Message ID 7df9cf69-0e75-53a7-d2d5-28b85ee78940@codethink.co.uk
State New
Headers show
Series Fortran : ICE in gfc_conv_scalarized_array_ref PR53298 | expand

Commit Message

Mark Eggleston July 20, 2020, 7:27 a.m. UTC
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 <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-20  Mark Eggleston <markeggleston@gcc.gnu.org>

gcc/testsuite/

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

Comments

Mark Eggleston July 28, 2020, 8:01 a.m. UTC | #1
ping

On 20/07/2020 08:27, Mark Eggleston wrote:
> 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 <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-20  Mark Eggleston <markeggleston@gcc.gnu.org>
>
> gcc/testsuite/
>
>     PR fortran/53298
>     * gfortran.dg/pr53298.f90: New test.
>
Thomas Koenig July 28, 2020, 8:37 p.m. UTC | #2
Hi Mark,

>> Please find attached a fix for PR53298.

OK.

Thanks for the patch!

Regards

	Thomas
diff mbox series

Patch

From aa1537ffa55d2c85c1f61df3301182627ca35ca3 Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggleston@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  <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-20  Mark Eggleston  <markeggleston@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