public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, fortran] Fix type conversion in large array constructors with iterators
@ 2018-03-18 22:23 Thomas König
  2018-03-18 23:20 ` Steve Kargl
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas König @ 2018-03-18 22:23 UTC (permalink / raw)
  To: fortran, gcc-patches

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

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.

[-- Attachment #2: p2.diff --]
[-- Type: text/x-patch, Size: 1204 bytes --]

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;

[-- Attachment #3: array_constructor_52.f90 --]
[-- Type: text/x-fortran, Size: 280 bytes --]

! { dg-do  run }
! PR 84931 - long array constructors with type conversion were not
! handled correctly.
program test
   implicit none
   integer, parameter :: n = 2**16
   real, dimension(n) :: y
   integer :: i
   y = (/ (1, i=1, n) /)
   if (y(2) /= 1) stop 1
end program test

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

* Re: [patch, fortran] Fix type conversion in large array constructors with iterators
  2018-03-18 22:23 [patch, fortran] Fix type conversion in large array constructors with iterators Thomas König
@ 2018-03-18 23:20 ` Steve Kargl
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Kargl @ 2018-03-18 23:20 UTC (permalink / raw)
  To: Thomas König; +Cc: fortran, gcc-patches

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.

-- 
Steve

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

end of thread, other threads:[~2018-03-18 23:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-18 22:23 [patch, fortran] Fix type conversion in large array constructors with iterators Thomas König
2018-03-18 23:20 ` Steve Kargl

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).