diff mbox series

[fortran] Fix the rest of PR 59345

Message ID f7c9e7e8-0a87-4b40-3ad9-b41e215175db@netcologne.de
State New
Headers show
Series [fortran] Fix the rest of PR 59345 | expand

Commit Message

Thomas Koenig Jan. 12, 2019, 9:09 p.m. UTC
Hello world,

this patch fixes the rest of the PR by making sure we do not
pack/unpack for function results which are either allocatable
or explicit shape arrays.

Regression-tested. OK for trunk?

Regards

	Thomas

2019-01-12  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/59345
         * trans-array.c (gfc_conv_array_parameter): Remove TODO.  Do not
         pack/unpack results of functions which return an explicit-shaped
         or allocatable array.

2019-01-12  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/59345
         * gfortran.dg/internal_pack_17.f90: New test.
         * gfortran.dg/alloc_comp_auto_array_3.f90: Adjust number of calls
         to builtin_free.

Comments

Steve Kargl Jan. 13, 2019, 3:56 a.m. UTC | #1
On Sat, Jan 12, 2019 at 10:09:14PM +0100, Thomas Koenig wrote:
> Hello world,
> 
> this patch fixes the rest of the PR by making sure we do not
> pack/unpack for function results which are either allocatable
> or explicit shape arrays.
> 
> Regression-tested. OK for trunk?
> 

OK.
diff mbox series

Patch

Index: trans-array.c
===================================================================
--- trans-array.c	(Revision 267829)
+++ trans-array.c	(Arbeitskopie)
@@ -7740,7 +7740,6 @@  array_parameter_size (tree desc, gfc_expr *expr, t
 }
 
 /* Convert an array for passing as an actual parameter.  */
-/* TODO: Optimize passing g77 arrays.  */
 
 void
 gfc_conv_array_parameter (gfc_se * se, gfc_expr * expr, bool g77,
@@ -7866,11 +7865,23 @@  gfc_conv_array_parameter (gfc_se * se, gfc_expr *
 
   no_pack = contiguous && no_pack;
 
-  /* If we have an expression, an array temporary will be
-     generated which does not need to be packed / unpacked
-     if passed to an explicit-shape dummy array.  */
+  /* If we have an EXPR_OP or a function returning an explicit-shaped
+     or allocatable array, an array temporary will be generated which
+     does not need to be packed / unpacked if passed to an
+     explicit-shape dummy array.  */
 
-  no_pack = no_pack || (g77 && expr->expr_type == EXPR_OP);
+  if (g77)
+    {
+      if (expr->expr_type == EXPR_OP)
+	no_pack = 1;
+      else if (expr->expr_type == EXPR_FUNCTION && expr->value.function.esym)
+	{
+	  gfc_symbol *result = expr->value.function.esym->result;
+	  if (result->attr.dimension
+	      && (result->as->type == AS_EXPLICIT || result->attr.allocatable))
+	    no_pack = 1;
+	}
+    }
 
   /* Array constructors are always contiguous and do not need packing.  */
   array_constructor = g77 && !this_array_result && expr->expr_type == EXPR_ARRAY;