aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Vehreschild <vehre@gcc.gnu.org>2015-11-27 14:08:23 +0000
committerAndre Vehreschild <vehre@gcc.gnu.org>2015-11-27 14:08:23 +0000
commit0befe1f821a555a968b249f6d987f0d52a69da81 (patch)
tree535f273c998fc8c8385324ee58fe79fda9304507
parentdef63c958923702169ca0bb69e23617903b097db (diff)
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. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/gcc-5-branch@231014 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/fortran/ChangeLog6
-rw-r--r--gcc/fortran/trans-array.c2
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/allocate_with_arrayspec_1.f9029
4 files changed, 42 insertions, 0 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index c746e163fe4..7029af0b5f6 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -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.
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 9c175b1d480..3c2c64046e4 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/ChangeLog b/gcc/testsuite/ChangeLog
index 8c04ab61fe5..89dcd4fcc7f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
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 00000000000..686b612408a
--- /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" } }