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

Paul Richard Thomas paul.richard.thomas@gmail.com
Tue Oct 13 09:34:00 GMT 2009


Janus,

This looks OK to me except for one thing:

A number of local gfc_expr's are created by copying but they are not
subsequently free'd; eg.
in gfc_trans_class_assign we find

+      gfc_expr *lhs,*rhs;
+      lhs = gfc_copy_expr (code->expr1);  .....etc.

without an associated gfc_free_expr (lhs).

Could you please check all the local expression creation and remedy
the memory leaks, before committing.

Thanks

Paul

On Mon, Oct 12, 2009 at 3:56 PM, Janus Weil <janus@gcc.gnu.org> wrote:
> 2009/10/12 Janus Weil <janus@gcc.gnu.org>:
>> here is my patch for the correct allocation of CLASS variables.
>
> Update: The attached version fixes the default initialization for the
> first ALLOCATE statement in the test case (also via memcpy) and
> corrects a few overlong lines. It still passes the regtest.
>
> Cheers,
> Janus
>
>
>
>> 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.
>>
>



-- 
The knack of flying is learning how to throw yourself at the ground and miss.
       --Hitchhikers Guide to the Galaxy



More information about the Gcc-patches mailing list