diff options
author | Erik Edelmann <eedelman@gcc.gnu.org> | 2006-02-12 17:34:15 +0000 |
---|---|---|
committer | Erik Edelmann <eedelman@gcc.gnu.org> | 2006-02-12 17:34:15 +0000 |
commit | 5b0b72518b76d75ad93ac95e6e05e772124085df (patch) | |
tree | 567b946985b670e7b860c5ac6728f1f803b19ebb /gcc/fortran/trans-array.c | |
parent | cac90078ea4d95125ad7e45c610d3859dfc1d164 (diff) | |
download | gcc-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-array.c')
-rw-r--r-- | gcc/fortran/trans-array.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 1edc7b7..5e8238b 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -479,9 +479,9 @@ gfc_set_loop_bounds_from_array_spec (gfc_interface_mapping * mapping, /* Generate code to allocate an array temporary, or create a variable to - hold the data. If size is NULL zero the descriptor so that so that the - callee will allocate the array. Also generates code to free the array - afterwards. + hold the data. If size is NULL, zero the descriptor so that the + callee will allocate the array. If DEALLOC is true, also generate code to + free the array afterwards. Initialization code is added to PRE and finalization code to POST. DYNAMIC is true if the caller may want to extend the array later @@ -489,8 +489,8 @@ gfc_set_loop_bounds_from_array_spec (gfc_interface_mapping * mapping, static void gfc_trans_allocate_array_storage (stmtblock_t * pre, stmtblock_t * post, - gfc_ss_info * info, tree size, tree nelem, - bool dynamic) + gfc_ss_info * info, tree size, tree nelem, + bool dynamic, bool dealloc) { tree tmp; tree args; @@ -546,7 +546,7 @@ gfc_trans_allocate_array_storage (stmtblock_t * pre, stmtblock_t * post, tmp = gfc_conv_descriptor_offset (desc); gfc_add_modify_expr (pre, tmp, gfc_index_zero_node); - if (!onstack) + if (dealloc && !onstack) { /* Free the temporary. */ tmp = gfc_conv_descriptor_data_get (desc); @@ -565,12 +565,13 @@ gfc_trans_allocate_array_storage (stmtblock_t * pre, stmtblock_t * post, Also fills in the descriptor, data and offset fields of info if known. Returns the size of the array, or NULL for a callee allocated array. - PRE, POST and DYNAMIC are as for gfc_trans_allocate_array_storage. */ + PRE, POST, DYNAMIC and DEALLOC are as for gfc_trans_allocate_array_storage. + */ tree gfc_trans_allocate_temp_array (stmtblock_t * pre, stmtblock_t * post, - gfc_loopinfo * loop, gfc_ss_info * info, - tree eltype, bool dynamic) + gfc_loopinfo * loop, gfc_ss_info * info, + tree eltype, bool dynamic, bool dealloc) { tree type; tree desc; @@ -665,7 +666,8 @@ gfc_trans_allocate_temp_array (stmtblock_t * pre, stmtblock_t * post, size = fold_build2 (MULT_EXPR, gfc_array_index_type, size, TYPE_SIZE_UNIT (gfc_get_element_type (type))); - gfc_trans_allocate_array_storage (pre, post, info, size, nelem, dynamic); + gfc_trans_allocate_array_storage (pre, post, info, size, nelem, dynamic, + dealloc); if (info->dimen > loop->temp_dim) loop->temp_dim = info->dimen; @@ -1416,7 +1418,7 @@ gfc_trans_array_constructor (gfc_loopinfo * loop, gfc_ss * ss) } gfc_trans_allocate_temp_array (&loop->pre, &loop->post, loop, - &ss->data.info, type, dynamic); + &ss->data.info, type, dynamic, true); desc = ss->data.info.descriptor; offset = gfc_index_zero_node; @@ -2832,7 +2834,8 @@ gfc_conv_loop_setup (gfc_loopinfo * loop) loop->temp_ss->type = GFC_SS_SECTION; loop->temp_ss->data.info.dimen = n; gfc_trans_allocate_temp_array (&loop->pre, &loop->post, loop, - &loop->temp_ss->data.info, tmp, false); + &loop->temp_ss->data.info, tmp, false, + true); } for (n = 0; n < loop->temp_dim; n++) |