This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Fortran, patch, pr68218, backport to 5 and 4.9, v1] ALLOCATE with size given by a module function


Hi Mikael, hi all,

Mikael, thanks for the fast review.

Committed after sync with richi for 5.3 as r231014 and r231017 for 4.9.

Regards,
	Andre

On Fri, 27 Nov 2015 14:09:15 +0100
Mikael Morin <mikael.morin@sfr.fr> wrote:

> Le 27/11/2015 13:20, Andre Vehreschild a Ãcrit :
> > Hi all,
> >
> > I have backported the patch for 68218 (multiple calls of the same
> > function, where only one call is expected and reasonable) to
> > gcc-5-branch and gcc-4_9-branch.
> >
> > Bootstrapped and regtested on x86_64-linux-gnu/f21.
> >
> > Ok for gcc-5-branch?
> >
> > Ok for gcc-4_9-branch?
> >
> Yes for both.
> Richi said in [1] that a 5.3 release candidate was planned for either 
> today or next monday, so before proceeding, please ping one release 
> manager on IRC to check that your commit won't interfere with the 
> release process.
> Thanks
> 
> Mikael
> 
> [1] https://gcc.gnu.org/ml/gcc/2015-11/msg00186.html


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 
Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 231014)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,9 @@
+2015-11-27  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	PR fortran/68218
+	* trans-array.c (gfc_array_init_size): Add gfc_evaluate_now() when
+	array spec in allocate is a function call.
+
 2015-11-25  Paul Thomas  <pault@gcc.gnu.org>
 
 	Backport from trunk.
Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c	(Revision 231014)
+++ gcc/fortran/trans-array.c	(Arbeitskopie)
@@ -4976,6 +4976,8 @@
       gcc_assert (ubound);
       gfc_conv_expr_type (&se, ubound, gfc_array_index_type);
       gfc_add_block_to_block (pblock, &se.pre);
+      if (ubound->expr_type == EXPR_FUNCTION)
+	se.expr = gfc_evaluate_now (se.expr, pblock);
 
       gfc_conv_descriptor_ubound_set (descriptor_block, descriptor,
 				      gfc_rank_cst[n], se.expr);
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 231014)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,8 @@
+2015-11-27  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	PR fortran/68218
+	* gfortran.dg/allocate_with_arrayspec_1.f90: New test.
+
 2015-11-26  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
 	Backport from mainline
Index: gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90	(Arbeitskopie)
@@ -0,0 +1,29 @@
+! { dg-do run }
+! { dg-options "-fdump-tree-original" }
+
+MODULE mo_test
+
+  integer :: n = 0
+CONTAINS
+
+  FUNCTION nquery()
+    INTEGER :: nquery
+    WRITE (0,*) "hello!"
+    n = n + 1
+    nquery = n
+  END FUNCTION nquery
+
+END MODULE mo_test
+
+
+! ----------------------------------------------------------------------
+! MAIN PROGRAM
+! ----------------------------------------------------------------------
+PROGRAM example
+   USE mo_test
+   INTEGER, ALLOCATABLE :: query_buf(:)
+   ALLOCATE(query_buf(nquery()))
+   if (n /= 1 .or. size(query_buf) /= n) call abort()
+END PROGRAM example
+
+! { dg-final { scan-tree-dump-times "nquery" 5 "original" } }
Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 231012)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,9 @@
+2015-11-27  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	PR fortran/68218
+	* trans-array.c (gfc_array_init_size): Add gfc_evaluate_now() when
+	array spec in allocate is a function call.
+
 2015-11-24  Paul Thomas  <pault@gcc.gnu.org>
 
 	Backport from trunk.
Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c	(Revision 231012)
+++ gcc/fortran/trans-array.c	(Arbeitskopie)
@@ -5030,6 +5030,8 @@
       gcc_assert (ubound);
       gfc_conv_expr_type (&se, ubound, gfc_array_index_type);
       gfc_add_block_to_block (pblock, &se.pre);
+      if (ubound->expr_type == EXPR_FUNCTION)
+	se.expr = gfc_evaluate_now (se.expr, pblock);
 
       gfc_conv_descriptor_ubound_set (descriptor_block, descriptor,
 				      gfc_rank_cst[n], se.expr);
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 231012)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,8 @@
+2015-11-27  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	PR fortran/68218
+	* gfortran.dg/allocate_with_arrayspec_1.f90: New test.
+
 2015-11-27  Jakub Jelinek  <jakub@redhat.com>
 
 	PR rtl-optimization/68250
Index: gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90	(Arbeitskopie)
@@ -0,0 +1,29 @@
+! { dg-do run }
+! { dg-options "-fdump-tree-original" }
+
+MODULE mo_test
+
+  integer :: n = 0
+CONTAINS
+
+  FUNCTION nquery()
+    INTEGER :: nquery
+    WRITE (0,*) "hello!"
+    n = n + 1
+    nquery = n
+  END FUNCTION nquery
+
+END MODULE mo_test
+
+
+! ----------------------------------------------------------------------
+! MAIN PROGRAM
+! ----------------------------------------------------------------------
+PROGRAM example
+   USE mo_test
+   INTEGER, ALLOCATABLE :: query_buf(:)
+   ALLOCATE(query_buf(nquery()))
+   if (n /= 1 .or. size(query_buf) /= n) call abort()
+END PROGRAM example
+
+! { dg-final { scan-tree-dump-times "nquery" 5 "original" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]