diff mbox series

[fortran] Fix PR 85111, some more zero size stuff

Message ID 7c4b20d0-7f21-632c-197f-7d5e89f0a61a@netcologne.de
State New
Headers show
Series [fortran] Fix PR 85111, some more zero size stuff | expand

Commit Message

Thomas Koenig March 29, 2018, 6:07 p.m. UTC
Hello world,

the attached patch fixes PR 85111, a regression introduced with my
recent simplification patches.  Seems like the zero-size saga
has yet another chapter :-)

Regression-tested. OK for trunk?

Regards

	Thomas

2017-03-29  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/85111
         * array.c (gfc_resolve_character_array_constructor): Early
         exit for zero-size arrays.
         * simplify.c (simplify_transformation_to_array): Exit early
         if the result size is zero.
         (simplify_minmaxloc_to_array): Likewise.

2017-03-29  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/85111
         * gfortran.dg/zero_sized_10.f90: New test.

Comments

Jerry DeLisle March 30, 2018, 2:30 a.m. UTC | #1
On 03/29/2018 11:07 AM, Thomas Koenig wrote:
> Hello world,
> 
> the attached patch fixes PR 85111, a regression introduced with my
> recent simplification patches.  Seems like the zero-size saga
> has yet another chapter :-)
> 
> Regression-tested. OK for trunk?
> 

Looks OK,

Thanks,

Jerry
> Regards
> 
>      Thomas
> 
> 2017-03-29  Thomas Koenig  <tkoenig@gcc.gnu.org>
> 
>          PR fortran/85111
>          * array.c (gfc_resolve_character_array_constructor): Early
>          exit for zero-size arrays.
>          * simplify.c (simplify_transformation_to_array): Exit early
>          if the result size is zero.
>          (simplify_minmaxloc_to_array): Likewise.
> 
> 2017-03-29  Thomas Koenig  <tkoenig@gcc.gnu.org>
> 
>          PR fortran/85111
>          * gfortran.dg/zero_sized_10.f90: New test.
diff mbox series

Patch

Index: array.c
===================================================================
--- array.c	(revision 258845)
+++ array.c	(working copy)
@@ -2003,6 +2003,20 @@  gfc_resolve_character_array_constructor (gfc_expr
 
 got_charlen:
 
+  /* Early exit for zero size arrays. */
+  if (expr->shape)
+    {
+      mpz_t size;
+      HOST_WIDE_INT arraysize;
+
+      gfc_array_size (expr, &size);
+      arraysize = mpz_get_ui (size);
+      mpz_clear (size);
+
+      if (arraysize == 0)
+	return true;
+    }
+
   found_length = -1;
 
   if (expr->ts.u.cl->length == NULL)
Index: simplify.c
===================================================================
--- simplify.c	(revision 258845)
+++ simplify.c	(working copy)
@@ -627,7 +627,7 @@  simplify_transformation_to_array (gfc_expr *result
       n += 1;
     }
 
-  done = false;
+  done = resultsize <= 0;
   base = arrayvec;
   dest = resultvec;
   while (!done)
@@ -5304,7 +5304,7 @@  simplify_minmaxloc_to_array (gfc_expr *result, gfc
       n += 1;
     }
 
-  done = false;
+  done = resultsize <= 0;
   base = arrayvec;
   dest = resultvec;
   while (!done)