[Patch, fortran] PR61831 side-effect deallocation of variable components

Mikael Morin mikael.morin@sfr.fr
Sat May 16 17:01:00 GMT 2015


Hello,

this is about PR61831 where in code like:
	
	type :: string_t
	   character(LEN=1), dimension(:), allocatable :: chars
	end type string_t
	type(string_t) :: prt_in
	(...)
	tmp = new_prt_spec ([prt_in])
	
the deallocation of the argument's allocatable components after the
procedure call (to new_prt_spec) has the side effect of freeing prt_in's
allocatable components, as the array constructor temporary for [prt_in]
is a shallow copy of prt_in.

This bug is a regression caused by the Dominique's PR41936 memory leak
fix, itself based on a patch originally from me.

The attached patch is basically a revert of that fix.  It avoids the
problem by not deallocating allocatable components in the problematic
case, at the price of a (possible) memory leak.  A new function is
introduced telling whether there is aliasing, so that we don't regress
on PR41936's memory leak when there is no aliasing, and we don't free
components when there is aliasing.
The possible remaining memory leak case is the case of a "mixed" array
constructor with some parts aliasing variables, and some non-aliasing parts.

The patch takes also the opportunity to reassemble the scattered
procedure argument deallocation code into a single place.

The test needs pr65792's fix (thanks Paul), so for the 4.9 branch I
propose commenting the parts that depend on PR65792 in the test.

Regression tested on x86_64-linux. OK for 6/5/4.9 ?

Mikael





-------------- next part --------------
2015-05-16  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/61831
	* trans-array.c (gfc_conv_array_parameter): Remove allocatable
	component deallocation code generation.
	* trans-expr.c (gfc_conv_expr_reference): Ditto.
	(expr_may_alias_variables): New function.
	(gfc_conv_procedure_call): Use it to decide whether generate
	allocatable component deallocation code.
	(gfc_trans_subarray_assign): Set deep copy flag.

2015-05-16  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/61831
	* gfortran.dg/derived_constructor_components_6.f90: New.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr61831_v6.diff
Type: text/x-patch
Size: 3885 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20150516/046fd32c/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: derived_constructor_comps_6.f90
Type: text/x-fortran
Size: 4582 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20150516/046fd32c/attachment-0001.bin>


More information about the Gcc-patches mailing list