This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

[gfortran, patch] PR 25806: Functions returning pointers to arrays


:ADDPATCH fortran:

Here's a patch for PR 25806.  There are actually two problems:

1) When printing the result of a PTA (Pointer To Array) function,
or passing the result of a PTA function to another procedure (and
perhaps other cases), we create a temporary array descriptor to
hold the result, and then we free the data pointer of the
temporary descriptor afterwards.  The freeing is a wrong thing to
do, because the data pointer is just set to point to the same
array as the function result points to (a shallow copy, in other
words).

Solution: Modify trans-array.c (gfc_trans_allocate_array_storage)
to optionally omit the freeing of the temporary, and use that
capability for PTA functions.

2) When assigning the result of an PTA function to an array 's', we
set the data pointer of the result to point to 's', call the PTA
function that just reassigns the data pointer to wthever it wants
it to point to, with the result that 's' is left unchanged.  The
solution is to use a temporary, and copy from it to 's' (achieved
by returning NULL from trans-expr.c
(gfc_trans_arrayfunc_assign)).


Tested on Linux/x86, on mainline and 4.1.  Ok for mainline? and
4.1 one day later?


        Erik



2006-02-05  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.


2006-02-05  Erik Edelmann  <eedelman@gcc.gnu.org>

	PR fortran/25806
	* gfortran.dg/ret_pointer_2.f90: New test.

Attachment: 25806.diff
Description: Text document

Attachment: ret_pointer_2.f90
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]