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] |
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
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:
pr68218_v5_1.clog
Description: Binary data
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" } }
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |