[Patch, fortran] PR63205 - [OOP] Wrongly rejects type = class (for identical declared type)
Tobias Burnus
burnus@net-b.de
Thu Jan 29 22:35:00 GMT 2015
Paul Richard Thomas wrote:
> ping!
[...]
> Outside of a dog, a book is a man's best friend. Inside of a dog it's
> too dark to read.
>
> Groucho Marx
It has been pointed out that with the advent of ebook readers, the
latter is no longer true. Additionally, it is uncertain whether he
actually said this nice quip â he actually might. In any case the
slightly modified version was already attributed to Jim Brewer in 1954
("A book is manâs best friend outside of a dog, and inside of a dog itâs
too dark to read."). Cf. http://quoteinvestigator.com/2010/09/08/dog/
Coming back to more mundane issues:
Paul Richard Thomas wrote:
> This patch enables the passing of an allocatable class object, scalar
> or array, to a derived type of the declared type, either in an
> assignment or as an actual argument. Much of the effort went into
> sorting out the finalization call so that the 'left over' allocatable
> components added by the dynamic type do not leak memory.
>
> Note that adding the 'must_finalize' field to gfc_expr will be useful
> in enabling the missing mandatory finalization calls.
Only vaguely related to your patch:
Do you know whether allocatable scalars (non polymorphic) returned as
function results are meanwhile deallocated/finalized after their use?
(At least for intrinsic types, this not only occurs for "a = f()" but
also in other expressions "f() + 5"; as with derived types, "call
foo(f())" also needs to be handled.)
Talking further about finalization, I think for "a = ...", the
finalization of "a" also didn't work. (Surely not working is
co_broadcast finalization â which is simple; and for co_reduce, I still
have no idea how to implement it [both the generic co_reduce and the
finalization].)
> There are still interrogation marks about the patch; especially in
> build_class_array_ref, where I do not understand why the added code
> does not work in general, except for hidden function results.
I have to admit that I am half-lost with that part of the code.
> Bootstraps and regtests on x86_64/FC21 - OK for trunk?
>
>
> ! /* For a function with a class array result, save the result as
> ! a temporary, set the info fields needed by the scalarizer and
> ! call the finalization function of the temporary. Note that the
> ! nullification of allocatable components needed by the result
> ! is done in gfc_trans_assignment_1. */
Here, the indentation seems to be off.
I think the patch is okay â at least I couldn't spot anything worrisome;
hopefully, we didn't miss anything.
Thanks for actively working on the loose ends and the regressions!
Tobias
PS: As a side note, I think there are also some issues with assumed-rank
arrays and type <-> class handling.
> 2015-01-27 Paul Thomas<pault@gcc.gnu.org>
>
> PR fortran/63205
> * gfortran.h: Add 'must finalize' field to gfc_expr and
> prototypes for gfc_is_alloc_class_scalar_function and for
> gfc_is_alloc_class_array_function.
> * expr.c (gfc_is_alloc_class_scalar_function,
> gfc_is_alloc_class_array_function): New functions.
> * trans-array.c (gfc_add_loop_ss_code): Do not move the
> expression for allocatable class scalar functions outside the
> loop.
> (conv_array_index_offset): Cope with deltas being NULL_TREE.
> (build_class_array_ref): Do not return with allocatable class
> array functions. Add code to pick out the returned class array.
> Dereference if necessary and return if not a class object.
> (gfc_conv_scalarized_array_ref): Cope with offsets being NULL.
> (gfc_walk_function_expr): Return an array ss for the result of
> an allocatable class array function.
> * trans-expr.c (gfc_conv_subref_array_arg): Remove the assert
> that the argument should be a variable. If an allocatable class
> array function, set the offset to zero and skip the write-out
> loop in this case.
> (gfc_conv_procedure_call): Add allocatable class array function
> to the assert. Call gfc_conv_subref_array_arg for allocatable
> class array function arguments with derived type formal arg..
> Add the code for handling allocatable class functions, including
> finalization calls to prevent memory leaks.
> (arrayfunc_assign_needs_temporary): Return if an allocatable
> class array function.
> (gfc_trans_assignment_1): Set must_finalize to rhs expression
> for allocatable class functions. Set scalar_to_array as needed
> for scalar class allocatable functions assigned to an array.
> Nullify the allocatable components corresponding the the lhs
> derived type so that the finalization does not free them.
>
> 2015-01-27 Paul Thomas<pault@gcc.gnu.org>
>
> PR fortran/63205
> * gfortran.dg/class_to_type_4.f90: New test
More information about the Fortran
mailing list