public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Fortran, patch, pr68218, v1] ALLOCATE with size given by a module function
@ 2015-11-05 14:29 Andre Vehreschild
  2015-11-07 13:58 ` Paul Richard Thomas
  0 siblings, 1 reply; 5+ messages in thread
From: Andre Vehreschild @ 2015-11-05 14:29 UTC (permalink / raw)
  To: GCC-Patches-ML, GCC-Fortran-ML

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

Hi all,

attached is a rather trivial patch to prevent multiple evaluations of a
function in:

  allocate( array(func()) )

The patch tests whether the upper bound of the array is a function
and calls gfc_evaluate_now().

Bootstrapped and regtested for x86_64-linux-gnu/f21.

Ok for trunk?

Regards,
	Andre
-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: pr68218_1.clog --]
[-- Type: application/octet-stream, Size: 361 bytes --]

gcc/fortran/ChangeLog:

2015-11-05  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.

gcc/testsuite/ChangeLog:

2015-11-05  Andre Vehreschild  <vehre@gcc.gnu.org>

	PR fortran/68218
	* gfortran.dg/allocate_with_arrayspec_1.f90: New test.



[-- Attachment #3: pr68218_1.patch --]
[-- Type: text/x-patch, Size: 1534 bytes --]

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 6bbf8cc..e28a5ce 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -5150,6 +5150,8 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset,
 	  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);
diff --git a/gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90 b/gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90
new file mode 100644
index 0000000..686b612
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90
@@ -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" } }

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

* Re: [Fortran, patch, pr68218, v1] ALLOCATE with size given by a module function
  2015-11-05 14:29 [Fortran, patch, pr68218, v1] ALLOCATE with size given by a module function Andre Vehreschild
@ 2015-11-07 13:58 ` Paul Richard Thomas
       [not found]   ` <20151108184850.6fe0ad54@vepi2>
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Richard Thomas @ 2015-11-07 13:58 UTC (permalink / raw)
  To: Andre Vehreschild; +Cc: GCC-Patches-ML, GCC-Fortran-ML

Dear Andre,

OK for trunk.

I understand that you have investigated the issue(s) reported to you
by Dominique and can find no sign of them.

Thanks

Paul

On 5 November 2015 at 15:29, Andre Vehreschild <vehre@gmx.de> wrote:
> Hi all,
>
> attached is a rather trivial patch to prevent multiple evaluations of a
> function in:
>
>   allocate( array(func()) )
>
> The patch tests whether the upper bound of the array is a function
> and calls gfc_evaluate_now().
>
> Bootstrapped and regtested for x86_64-linux-gnu/f21.
>
> Ok for trunk?
>
> Regards,
>         Andre
> --
> Andre Vehreschild * Email: vehre ad gmx dot de



-- 
Outside of a dog, a book is a man's best friend. Inside of a dog it's
too dark to read.

Groucho Marx

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

* Re: [Fortran, patch, pr68218, backport to 5 and 4.9, v1] ALLOCATE with size given by a module function
       [not found]   ` <20151108184850.6fe0ad54@vepi2>
@ 2015-11-27 12:20     ` Andre Vehreschild
  2015-11-27 13:09       ` Mikael Morin
  0 siblings, 1 reply; 5+ messages in thread
From: Andre Vehreschild @ 2015-11-27 12:20 UTC (permalink / raw)
  To: GCC-Patches-ML, GCC-Fortran-ML

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

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?

The Changelog is identical for both patches. The patches are mostly,
too, just a slight shift.

Regards,
	Andre

On Sun, 8 Nov 2015 18:48:50 +0100
Andre Vehreschild <vehre@gmx.de> wrote:

> Hi Paul,
> 
> thanks for the review. Comitted as r229956.
> 
> In 5 and 4.9 the same issue exists. Currently checking whether the same
> patch helps.
> 
> Regards,
> 	Andre
> 
> On Sat, 7 Nov 2015 14:58:35 +0100
> Paul Richard Thomas <paul.richard.thomas@gmail.com> wrote:
> 
> > Dear Andre,
> > 
> > OK for trunk.
> > 
> > I understand that you have investigated the issue(s) reported to you
> > by Dominique and can find no sign of them.
> > 
> > Thanks
> > 
> > Paul
> > 
> > On 5 November 2015 at 15:29, Andre Vehreschild <vehre@gmx.de> wrote:
> > > Hi all,
> > >
> > > attached is a rather trivial patch to prevent multiple evaluations of a
> > > function in:
> > >
> > >   allocate( array(func()) )
> > >
> > > The patch tests whether the upper bound of the array is a function
> > > and calls gfc_evaluate_now().
> > >
> > > Bootstrapped and regtested for x86_64-linux-gnu/f21.
> > >
> > > Ok for trunk?
> > >
> > > Regards,
> > >         Andre
> > > --
> > > Andre Vehreschild * Email: vehre ad gmx dot de
> > 
> > 
> > 
> 
> 


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: pr68218_v4_9_1.patch --]
[-- Type: text/x-patch, Size: 1540 bytes --]

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 877e371..4928adf 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -4976,6 +4976,8 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset,
       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);
diff --git a/gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90 b/gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90
new file mode 100644
index 0000000..686b612
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90
@@ -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" } }

[-- Attachment #3: pr68218_v5_1.clog --]
[-- Type: application/octet-stream, Size: 361 bytes --]

gcc/fortran/ChangeLog:

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.

gcc/testsuite/ChangeLog:

2015-11-27  Andre Vehreschild  <vehre@gcc.gnu.org>

	PR fortran/68218
	* gfortran.dg/allocate_with_arrayspec_1.f90: New test.



[-- Attachment #4: pr68218_v5_1.patch --]
[-- Type: text/x-patch, Size: 1540 bytes --]

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 9c175b1..3c2c640 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -5030,6 +5030,8 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset,
       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);
diff --git a/gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90 b/gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90
new file mode 100644
index 0000000..686b612
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f90
@@ -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" } }

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

* Re: [Fortran, patch, pr68218, backport to 5 and 4.9, v1] ALLOCATE with size given by a module function
  2015-11-27 12:20     ` [Fortran, patch, pr68218, backport to 5 and 4.9, " Andre Vehreschild
@ 2015-11-27 13:09       ` Mikael Morin
  2015-11-27 14:38         ` Andre Vehreschild
  0 siblings, 1 reply; 5+ messages in thread
From: Mikael Morin @ 2015-11-27 13:09 UTC (permalink / raw)
  To: Andre Vehreschild, GCC-Patches-ML, GCC-Fortran-ML

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

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

* Re: [Fortran, patch, pr68218, backport to 5 and 4.9, v1] ALLOCATE with size given by a module function
  2015-11-27 13:09       ` Mikael Morin
@ 2015-11-27 14:38         ` Andre Vehreschild
  0 siblings, 0 replies; 5+ messages in thread
From: Andre Vehreschild @ 2015-11-27 14:38 UTC (permalink / raw)
  To: Mikael Morin; +Cc: GCC-Patches-ML, GCC-Fortran-ML

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

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 

[-- Attachment #2: submit_4.9.diff --]
[-- Type: text/x-patch, Size: 2404 bytes --]

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" } }

[-- Attachment #3: submit_5.diff --]
[-- Type: text/x-patch, Size: 2400 bytes --]

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" } }

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

end of thread, other threads:[~2015-11-27 14:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-05 14:29 [Fortran, patch, pr68218, v1] ALLOCATE with size given by a module function Andre Vehreschild
2015-11-07 13:58 ` Paul Richard Thomas
     [not found]   ` <20151108184850.6fe0ad54@vepi2>
2015-11-27 12:20     ` [Fortran, patch, pr68218, backport to 5 and 4.9, " Andre Vehreschild
2015-11-27 13:09       ` Mikael Morin
2015-11-27 14:38         ` Andre Vehreschild

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