From 5b0b72518b76d75ad93ac95e6e05e772124085df Mon Sep 17 00:00:00 2001 From: Erik Edelmann Date: Sun, 12 Feb 2006 17:34:15 +0000 Subject: re PR fortran/25806 (problems with functions returning array pointers?) fortran/ 2006-02-12 Erik Edelmann 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 PR fortran/25806 * gfortran.dg/ret_pointer_2.f90: New test. From-SVN: r110893 --- gcc/fortran/trans-expr.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'gcc/fortran/trans-expr.c') 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 -- cgit v1.1