[Patch, Fortran] PR 41581: [OOP] Allocation of a CLASS with SOURCE=<class> does not work

Janus Weil janus@gcc.gnu.org
Mon Oct 12 09:19:00 GMT 2009


Hi all,

here is my patch for the correct allocation of CLASS variables.

The primary issue here was that "ALLOCATE (a, SOURCE=b)" did not work
when both 'a' and 'b' are CLASS variables, since the size of the
memory to be allocated has to be determined at run time (depending on
the dynamic type of 'b'). For this purpose I introduce a $size field
in the CLASS container, which carries just this information and is
used to allocate the right amount of memory. It also must be set and
propagated correctly, e.g. in CLASS pointer assignments and CLASS
actual arguments.

But not only the size of the allocated memory is important, also this
memory must be initialized correctly when using SOURCE, which I do via
a 'memcpy'.

In the course of doing all this, I shifted some existing code around
for technical reasons. E.g. all the CLASS handling code in
resolve_allocate_expr and resolve_class_assign has been moved to
translation stage. [In general my recent patches seem to have a
tendency to defer stuff to later stages, which I hope is a good
thing.]

The patch was regtested on x86_64-unknown-linux-gnu with no failures.
Ok for trunk?

Cheers,
Janus


2009-10-12  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/41581
	* decl.c (encapsulate_class_symbol): Add new component '$size'.
	* resolve.c (resolve_allocate_expr): Move CLASS handling to
	gfc_trans_allocate.
	(resolve_class_assign): Replaced by gfc_trans_class_assign.
	(resolve_code): Remove calls to resolve_class_assign.
	* trans.c (gfc_trans_code): Use new function gfc_trans_class_assign.
	* trans-expr.c (gfc_conv_procedure_call): For CLASS dummies, set the
	$size component.
	(gfc_trans_class_assign): New function, replacing resolve_class_assign.
	* trans-stmt.h (gfc_trans_class_assign): New prototype.
	* trans-stmt.c (gfc_trans_allocate): Use correct size when allocating
	CLASS variables. Do proper initialization. Move some code here from
	resolve_allocate_expr.


2009-10-12  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/41581
	* gfortran.dg/class_allocate_2.f03: Modified.
	* gfortran.dg/class_allocate_3.f03: New test case.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr41581.diff
Type: text/x-diff
Size: 15006 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20091012/0836bca1/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: class_allocate_3.f03
Type: application/octet-stream
Size: 571 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20091012/0836bca1/attachment.obj>


More information about the Fortran mailing list