This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Fortran, patch, pr68218, backport to 5 and 4.9, v1] ALLOCATE with size given by a module function
- From: Andre Vehreschild <vehre at gmx dot de>
- To: Mikael Morin <mikael dot morin at sfr dot fr>
- Cc: GCC-Patches-ML <gcc-patches at gcc dot gnu dot org>, GCC-Fortran-ML <fortran at gcc dot gnu dot org>
- Date: Fri, 27 Nov 2015 15:38:10 +0100
- Subject: Re: [Fortran, patch, pr68218, backport to 5 and 4.9, v1] ALLOCATE with size given by a module function
- Authentication-results: sourceware.org; auth=none
- References: <20151105152920 dot 65f52c89 at vepi2> <CAGkQGiKC_Zmc_yhSOn3tyNsunR09q68tK-ZnNBKV6HVMWCWVYQ at mail dot gmail dot com> <20151108184850 dot 6fe0ad54 at vepi2> <20151127132022 dot 137034e4 at vepi2> <565855FB dot 1050501 at sfr dot fr>
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" } }
- References:
- [Fortran, patch, pr68218, v1] ALLOCATE with size given by a module function
- Re: [Fortran, patch, pr68218, v1] ALLOCATE with size given by a module function
- From: Paul Richard Thomas
- Re: [Fortran, patch, pr68218, backport to 5 and 4.9, v1] ALLOCATE with size given by a module function
- Re: [Fortran, patch, pr68218, backport to 5 and 4.9, v1] ALLOCATE with size given by a module function