PR fortran/90002 -- Free array-spec for assumed-shaped coarray

Message ID 20190612010340.GA29576@troutmask.apl.washington.edu
State New
Headers show
Series
  • PR fortran/90002 -- Free array-spec for assumed-shaped coarray
Related show

Commit Message

Steve Kargl June 12, 2019, 1:03 a.m.
The attached patch fixes an ICE when freeing an array-spec
that involves an assumed-shaped coarray (see testcase).  The
patch regression tests cleanly.  I don't use coarrays, so
cannot say whether the testcase is valid Fortran.  I simply
fixed the ICE.  OK to commit?

2019-06-11  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/90002
	* array.c (gfc_free_array_spec): When freeing an array-spec, avoid
	an ICE for assumed-shape coarrays 

2019-06-11  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/90002
	* gfortran.dg/pr90002.f90: New test.

-- 
Steve

Comments

Paul Richard Thomas June 12, 2019, 5:14 a.m. | #1
OK, Steve

Thanks

Paul

On Wed, 12 Jun 2019 at 02:04, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
>

> The attached patch fixes an ICE when freeing an array-spec

> that involves an assumed-shaped coarray (see testcase).  The

> patch regression tests cleanly.  I don't use coarrays, so

> cannot say whether the testcase is valid Fortran.  I simply

> fixed the ICE.  OK to commit?

>

> 2019-06-11  Steven G. Kargl  <kargl@gcc.gnu.org>

>

>         PR fortran/90002

>         * array.c (gfc_free_array_spec): When freeing an array-spec, avoid

>         an ICE for assumed-shape coarrays

>

> 2019-06-11  Steven G. Kargl  <kargl@gcc.gnu.org>

>

>         PR fortran/90002

>         * gfortran.dg/pr90002.f90: New test.

>

> --

> Steve




-- 
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein
Steve Kargl June 12, 2019, 6:28 p.m. | #2
Thanks.

Committed as revision  272201.

-- 
steve


On Wed, Jun 12, 2019 at 06:14:11AM +0100, Paul Richard Thomas wrote:
> OK, Steve

> 

> Thanks

> 

> Paul

> 

> On Wed, 12 Jun 2019 at 02:04, Steve Kargl

> <sgk@troutmask.apl.washington.edu> wrote:

> >

> > The attached patch fixes an ICE when freeing an array-spec

> > that involves an assumed-shaped coarray (see testcase).  The

> > patch regression tests cleanly.  I don't use coarrays, so

> > cannot say whether the testcase is valid Fortran.  I simply

> > fixed the ICE.  OK to commit?

> >

> > 2019-06-11  Steven G. Kargl  <kargl@gcc.gnu.org>

> >

> >         PR fortran/90002

> >         * array.c (gfc_free_array_spec): When freeing an array-spec, avoid

> >         an ICE for assumed-shape coarrays

> >

> > 2019-06-11  Steven G. Kargl  <kargl@gcc.gnu.org>

> >

> >         PR fortran/90002

> >         * gfortran.dg/pr90002.f90: New test.

> >

> > --

> > Steve

> 

> 

> 

> -- 

> "If you can't explain it simply, you don't understand it well enough"

> - Albert Einstein


-- 
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow

Patch

Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c	(revision 272173)
+++ gcc/fortran/array.c	(working copy)
@@ -324,10 +324,22 @@  gfc_free_array_spec (gfc_array_spec *as)
   if (as == NULL)
     return;
 
-  for (i = 0; i < as->rank + as->corank; i++)
+  if (as->corank == 0)
     {
-      gfc_free_expr (as->lower[i]);
-      gfc_free_expr (as->upper[i]);
+      for (i = 0; i < as->rank; i++)
+	{
+	  gfc_free_expr (as->lower[i]);
+	  gfc_free_expr (as->upper[i]);
+	}
+    }
+  else
+    {
+      int n = as->rank + as->corank - (as->cotype == AS_EXPLICIT ? 1 : 0);
+      for (i = 0; i < n; i++)
+	{
+	  gfc_free_expr (as->lower[i]);
+	  gfc_free_expr (as->upper[i]);
+	}
     }
 
   free (as);
Index: gcc/testsuite/gfortran.dg/pr90002.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr90002.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr90002.f90	(working copy)
@@ -0,0 +1,6 @@ 
+! { dg-do compile }
+! { dg-options "-fcoarray=single" }
+! Contributed by Arseny Solokha <asolokha at gmx dot de>
+module pc
+  integer, dimension(1) :: zw[1:1,1:*]
+end module pc