public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fortran : ICE in gfc_conv_scalarized_array_ref PR53298
@ 2020-07-20  7:27 Mark Eggleston
  2020-07-28  8:01 ` Mark Eggleston
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Eggleston @ 2020-07-20  7:27 UTC (permalink / raw)
  To: gcc-patches, fortran

[-- Attachment #1: Type: text/plain, Size: 1789 bytes --]

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.

-- 
https://www.codethink.co.uk/privacy.html


[-- Attachment #2: 0001-Fortran-ICE-in-gfc_conv_scalarized_array_ref-PR53298.patch --]
[-- Type: text/x-patch, Size: 2075 bytes --]

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fortran : ICE in gfc_conv_scalarized_array_ref PR53298
  2020-07-20  7:27 [PATCH] Fortran : ICE in gfc_conv_scalarized_array_ref PR53298 Mark Eggleston
@ 2020-07-28  8:01 ` Mark Eggleston
  2020-07-28 20:37   ` Thomas Koenig
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Eggleston @ 2020-07-28  8:01 UTC (permalink / raw)
  To: gcc-patches, fortran

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.
>
-- 
https://www.codethink.co.uk/privacy.html


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fortran : ICE in gfc_conv_scalarized_array_ref PR53298
  2020-07-28  8:01 ` Mark Eggleston
@ 2020-07-28 20:37   ` Thomas Koenig
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Koenig @ 2020-07-28 20:37 UTC (permalink / raw)
  To: Mark Eggleston, gcc-patches, fortran

Hi Mark,

>> Please find attached a fix for PR53298.

OK.

Thanks for the patch!

Regards

	Thomas

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-28 20:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20  7:27 [PATCH] Fortran : ICE in gfc_conv_scalarized_array_ref PR53298 Mark Eggleston
2020-07-28  8:01 ` Mark Eggleston
2020-07-28 20:37   ` Thomas Koenig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).