[Patch, Fortran] MOVE_ALLOC fixes

Tobias Burnus burnus@net-b.de
Mon Nov 28 14:22:00 GMT 2011


Dear all,

attached is an updated patch, I hadn't considered that the declared type 
of polymorphic arguments could be different. The middle end was not 
happy about:
   to = from
where "to" and "from" where different class containers. I was 
considering to force the assignment (via VIEW_CONVERT_EXPR), but Jakub 
warns that this might confuse tree-sra while the produced code will 
anyway consists of two pointer assignments. Hence, I now directly 
generate two pointer assignments (for _data and _vptr). (The patch only 
affects scalar polymorphic variables; for arrays, there were already two 
pointer  assignments.)

Build and regtested on x86-64-linux (trunk and trunk + Paul's patch).
OK?

Tobias

On 11/26/2011 02:50 PM, Tobias Burnus wrote:
> 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-v2.diff
Type: text/x-patch
Size: 10259 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20111128/21908cfe/attachment.bin>


More information about the Gcc-patches mailing list