diff mbox series

[fortran] Fix PR 72714, ICE on invalid

Message ID 139a19ae-78c7-f256-83c2-bcc190637862@netcologne.de
State New
Headers show
Series [fortran] Fix PR 72714, ICE on invalid | expand

Commit Message

Thomas Koenig March 3, 2019, 9:44 a.m. UTC
Hello world,

the attached patch fixes a 7/8/9 regression by rejecting an invalid
expression in coarray allocation that led to an ICE.  It also adds a few
more checks.

One point that is checked for is that, unlike normal arrays, coarrays
cannot be empty.

Regression-tested. OK for trunk and affected branches?

Regards

	Thomas

2019-03-02  Thomas Koenig  <tkoenig@gcc.gnu.org> 

 

         PR fortran/72714 

         * resolve.c (resolve_allocate_expr): Add some tests for 
coarrays.
 

2019-03-02  Thomas Koenig  <tkoenig@gcc.gnu.org> 

 

         PR fortran/72714 

         * gfortran.dg/coarray_allocate_11.f90: New test.

Comments

Paul Richard Thomas March 3, 2019, 1:07 p.m. UTC | #1
Hi Thomas,

This is good for trunk.

Thanks

Paul

On Sun, 3 Mar 2019 at 09:46, Thomas Koenig <tkoenig@netcologne.de> wrote:
>
> Hello world,
>
> the attached patch fixes a 7/8/9 regression by rejecting an invalid
> expression in coarray allocation that led to an ICE.  It also adds a few
> more checks.
>
> One point that is checked for is that, unlike normal arrays, coarrays
> cannot be empty.
>
> Regression-tested. OK for trunk and affected branches?
>
> Regards
>
>         Thomas
>
> 2019-03-02  Thomas Koenig  <tkoenig@gcc.gnu.org>
>
>
>
>          PR fortran/72714
>
>          * resolve.c (resolve_allocate_expr): Add some tests for
> coarrays.
>
>
> 2019-03-02  Thomas Koenig  <tkoenig@gcc.gnu.org>
>
>
>
>          PR fortran/72714
>
>          * gfortran.dg/coarray_allocate_11.f90: New test.
diff mbox series

Patch

Index: resolve.c
===================================================================
--- resolve.c	(Revision 269260)
+++ resolve.c	(Arbeitskopie)
@@ -7766,13 +7766,54 @@  resolve_allocate_expr (gfc_expr *e, gfc_code *code
 
   if (codimension)
     for (i = ar->dimen; i < ar->dimen + ar->codimen; i++)
-      if (ar->dimen_type[i] == DIMEN_THIS_IMAGE)
-	{
-	  gfc_error ("Coarray specification required in ALLOCATE statement "
-		     "at %L", &e->where);
-	  goto failure;
-	}
+      {
+	switch (ar->dimen_type[i])
+	  {
+	  case DIMEN_THIS_IMAGE:
+	    gfc_error ("Coarray specification required in ALLOCATE statement "
+		       "at %L", &e->where);
+	    goto failure;
 
+	  case  DIMEN_RANGE:
+	    if (ar->start[i] == 0 || ar->end[i] == 0)
+	      {
+		/* If ar->stride[i] is NULL, we issued a previous error.  */
+		if (ar->stride[i] == NULL)
+		  gfc_error ("Bad array specification in ALLOCATE statement "
+			     "at %L", &e->where);
+		goto failure;
+	      }
+	    else if (gfc_dep_compare_expr (ar->start[i], ar->end[i]) == 1)
+	      {
+		gfc_error ("Upper cobound is less than lower cobound at %L",
+			   &ar->start[i]->where);
+		goto failure;
+	      }
+	    break;
+
+	  case DIMEN_ELEMENT:
+	    if (ar->start[i]->expr_type == EXPR_CONSTANT)
+	      {
+		gcc_assert (ar->start[i]->ts.type == BT_INTEGER);
+		if (mpz_cmp_si (ar->start[i]->value.integer, 1) < 0)
+		  {
+		    gfc_error ("Upper cobound is less than lower cobound "
+			       " of 1 at %L", &ar->start[i]->where);
+		    goto failure;
+		  }
+	      }
+	    break;
+
+	  case DIMEN_STAR:
+	    break;
+
+	  default:
+	    gfc_error ("Bad array specification in ALLOCATE statement at %L",
+		       &e->where);
+	    goto failure;
+
+	  }
+      }
   for (i = 0; i < ar->dimen; i++)
     {
       if (ar->type == AR_ELEMENT || ar->type == AR_FULL)