aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/trans-expr.c
diff options
context:
space:
mode:
authorErik Edelmann <eedelman@gcc.gnu.org>2006-02-12 17:34:15 +0000
committerErik Edelmann <eedelman@gcc.gnu.org>2006-02-12 17:34:15 +0000
commit5b0b72518b76d75ad93ac95e6e05e772124085df (patch)
tree567b946985b670e7b860c5ac6728f1f803b19ebb /gcc/fortran/trans-expr.c
parentcac90078ea4d95125ad7e45c610d3859dfc1d164 (diff)
downloadgcc-5b0b72518b76d75ad93ac95e6e05e772124085df.zip
gcc-5b0b72518b76d75ad93ac95e6e05e772124085df.tar.gz
gcc-5b0b72518b76d75ad93ac95e6e05e772124085df.tar.bz2
re PR fortran/25806 (problems with functions returning array pointers?)
fortran/ 2006-02-12 Erik Edelmann <eedelman@gcc.gnu.org> PR fortran/25806 * trans-array.c (gfc_trans_allocate_array_storage): New argument dealloc; free the temporary only if dealloc is true. (gfc_trans_allocate_temp_array): New argument bool dealloc, to be passed onwards to gfc_trans_allocate_array_storage. (gfc_trans_array_constructor, gfc_conv_loop_setup): Update call to gfc_trans_allocate_temp_array. * trans-array.h (gfc_trans_allocate_temp_array): Update function prototype. * trans-expr.c (gfc_conv_function_call): Set new argument 'dealloc' to gfc_trans_allocate_temp_array to false in case of functions returning pointers. (gfc_trans_arrayfunc_assign): Return NULL for functions returning pointers. testsuite/ 2006-02-12 Erik Edelmann <eedelman@gcc.gnu.org> PR fortran/25806 * gfortran.dg/ret_pointer_2.f90: New test. From-SVN: r110893
Diffstat (limited to 'gcc/fortran/trans-expr.c')
-rw-r--r--gcc/fortran/trans-expr.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index d64dabe..3fbbf0e 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -1953,9 +1953,11 @@ gfc_conv_function_call (gfc_se * se, gfc_symbol * sym,
/* Evaluate the bounds of the result, if known. */
gfc_set_loop_bounds_from_array_spec (&mapping, se, sym->result->as);
- /* Allocate a temporary to store the result. */
- gfc_trans_allocate_temp_array (&se->pre, &se->post,
- se->loop, info, tmp, false);
+ /* Allocate a temporary to store the result. In case the function
+ returns a pointer, the temporary will be a shallow copy and
+ mustn't be deallocated. */
+ gfc_trans_allocate_temp_array (&se->pre, &se->post, se->loop, info,
+ tmp, false, !sym->attr.pointer);
/* Zero the first stride to indicate a temporary. */
tmp = gfc_conv_descriptor_stride (info->descriptor, gfc_rank_cst[0]);
@@ -2913,6 +2915,10 @@ gfc_trans_arrayfunc_assign (gfc_expr * expr1, gfc_expr * expr2)
if (gfc_ref_needs_temporary_p (expr1->ref))
return NULL;
+ /* Functions returning pointers need temporaries. */
+ if (expr2->symtree->n.sym->attr.pointer)
+ return NULL;
+
/* Check that no LHS component references appear during an array
reference. This is needed because we do not have the means to
span any arbitrary stride with an array descriptor. This check