https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81827

Luke Robison <robison at arlut dot utexas.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |robison at arlut dot utexas.edu

--- Comment #20 from Luke Robison <robison at arlut dot utexas.edu> ---
(In reply to Paul Thomas from comment #19)

Great to see some progress on this, I've been watching from the shadows since I
reported it :-).


> There are at least three sources of the recursive code:
> (i) The allocate statement. This checks to see if the allocate object and
> its allocatable components are allocated and deallocates them if 
> necessary. I must check if the standard requires this!

I do not believe the standard requires any deallocation before an allocate() is
executed (and I know from experience that trying to allocate an
already-allocated variable generally causes crashes).  The closest I see to
this case in the standard is Section 6.7.3.2 paragraph 7: "When an intrinsic
assignment statement is executed, any noncoarray allocated allocatable
subobject of the variable is deallocated before the assignment takes place". 
Which I interpret as being the "realloc-lhs" feature of F2003 (see 7.2.1.3 para
3), but I don't think that applies to the allocate statement itself.

> (ii) The vtable 'final' procedure. This calls any user defined 'final'
> procedures first, goes on to do the same for the allocatable components, 
> and then, after each 'final' call, dealloactes if necessary.
> (iii) The vtable 'copy'. This is a deep copy of the object and its
> allocatable components. It generates a load of code in consequence.

I completely agree for (ii) and (iii).

Additionally, there seems to be a similar case (iv), which I just noticed: When
an allocate is made with a source=<source-expr>.  This can be seen in 6.7.1.3
para 5: "When an object of derived type is created by an ALLOCATE statement,
any allocatable ultimate components have an allocation status of unallocated
*unless* the SOURCE= specifier appears and the corresponding component of the
source-expr is allocated." (emphasis mine).  I think this is probably
implemented as a call to the vtable 'copy', although it happens on an allocate.

> The answer is, yes, these recursive procedures are necessary. I just need
> to find some less compile time intensive way of implementing them.

With regards to the recursive allocation, it certainly does not need to happen
on an allocate statement without a source=* specifier, as seen in the
above-quote of 6.7.1.3 para 5, although as you point out there are other times
when it would be necessary.

I hope I've saved you some time digging through the standard.  I used this
version in my references:
  https://j3-fortran.org/doc/year/10/10-007r1.pdf

Reply via email to