[Patch, Fortran] MOVE_ALLOC fixes

Tobias Burnus burnus@net-b.de
Sat Nov 26 13:51:00 GMT 2011


Dear all,

(First, this is *not* for the 4.6/4.7 rejects-valid regression, which is 
related to intent(in) pointers with allocatable components.)

When debugging an issue with with polymorphic arrays and MOVE_ALLOC, I 
got lost in the code generation of move_alloc - and didn't like the 
generated code. Thus, I have rewritten the trans*.c part of it. (It 
turned out that the issue, we had, was unrelated to move_alloc.)

Changes:
* Replace call to libgfortran by inline code (much faster and shorter code)
* For arrays: Deallocate "from" (deep freeing)
* For polymorphic arrays: set _vptr.

Actually, the required code is rather simple: For move_alloc(from, to), 
one just needs to do:

a) Deallocate "to", taking allocatable components and the polymorphic 
types into account (the latter is a to-do item, cf. PR 46174).

b) Do a simple assignment:
    to = from
namely: If both are scalar variables, those are pointers and one does a 
pointer assignment. If they are polymorphic and/or an array, one does a 
(nonpointer) assignment to the class container or the array descriptor.

c) Setting "from = NULL" (nonpolymorphic scalars) or "from.data = NULL" 
(nonpolymorphic arrays) or "from._data = NULL" (polymorphic scalars) or 
"from._data.data = NULL" (polymorphic arrays).

For (b) the current expr-ref-walking function for polymorphic arrays 
either give access to class._data or to class._vptr. It is extremly 
difficult to access "class" itself. Thus, I now do two assignments: One 
nonpointer one to array descriptor and one pointer assignment to the _vptr.

Build and regtested with the trunk with Paul's polymorphic array patch 
applied. (I will do a bootstrap and regtest with a clean trunk before 
committal.)
OK for the trunk?

Tobias

PS: I'll add _gfortran_move_alloc to the list of functions which can be 
removed after the ABI breakage.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: move_alloc-inline.diff
Type: text/x-patch
Size: 9667 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20111126/186763fc/attachment.bin>


More information about the Fortran mailing list