[fortran] Fix type conversion in large array constructors with iterators
diff mbox series

Message ID 8d5c9fb1-5779-6871-5a80-18996dfd6d1b@tkoenig.net
State New
Headers show
Series
  • [fortran] Fix type conversion in large array constructors with iterators
Related show

Commit Message

Thomas König March 18, 2018, 10:23 p.m. UTC
Hello world,

the attached patch fixes the bug that Steve found; the patch itself
simply makes sure to copy a constructor instead of only the value
of the constructor when converting types.

Regressoin-tested. OK for trunk?

Maybe this is also a candidate for gcc-7, because of the silent
wrong-code issue.

Regards

	Thomas

2018-03-18  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/84931
         * simplify.c (gfc_convert_constant): Correctly handle iterators
         for type conversion.

2018-03-18  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/84931
         * gfortran.dg/array_constructor_52.f90: New test.

Comments

Steve Kargl March 18, 2018, 11:20 p.m. UTC | #1
On Sun, Mar 18, 2018 at 11:23:37PM +0100, Thomas König wrote:
> Hello world,
> 
> the attached patch fixes the bug that Steve found; the patch itself
> simply makes sure to copy a constructor instead of only the value
> of the constructor when converting types.
> 
> Regressoin-tested. OK for trunk?

Looks good to me.  Thanks for find the location to fix this.
I was off in the trees.

> 
> Maybe this is also a candidate for gcc-7, because of the silent
> wrong-code issue.
> 

As far as I am concerned, you can go back to 6-branch if the
patch applies cleanly.

Patch
diff mbox series

Index: simplify.c
===================================================================
--- simplify.c	(Revision 258501)
+++ simplify.c	(Arbeitskopie)
@@ -8016,26 +8016,32 @@  gfc_convert_constant (gfc_expr *e, bt type, int ki
 	{
 	  gfc_expr *tmp;
 	  if (c->iterator == NULL)
-	    tmp = f (c->expr, kind);
+	    {
+	      tmp = f (c->expr, kind);
+	      if (tmp == NULL)
+		{
+		  gfc_free_expr (result);
+		  return NULL;
+		}
+
+	      gfc_constructor_append_expr (&result->value.constructor,
+					   tmp, &c->where);
+	    }
 	  else
 	    {
+	      gfc_constructor *n;
 	      g = gfc_convert_constant (c->expr, type, kind);
-	      if (g == &gfc_bad_expr)
+	      if (g == NULL || g == &gfc_bad_expr)
 	        {
 		  gfc_free_expr (result);
 		  return g;
 		}
-	      tmp = g;
+	      n = gfc_constructor_get ();
+	      n->expr = g;
+	      n->iterator = gfc_copy_iterator (c->iterator);
+	      n->where = c->where;
+	      gfc_constructor_append (&result->value.constructor, n);
 	    }
-
-	  if (tmp == NULL)
-	    {
-	      gfc_free_expr (result);
-	      return NULL;
-	    }
-
-	  gfc_constructor_append_expr (&result->value.constructor,
-				       tmp, &c->where);
 	}
 
       break;