[patch,fortran] PR 16136: ALLOCATABLE dummy arguments
THOMAS Paul Richard 169137
paul.richard.thomas@cea.fr
Mon Mar 6 15:35:00 GMT 2006
Erik and Steve,
First of all, well done on making a start on this important extension.
What you have done works fine. However, the patch is incomplete in two
aspects, the first quite important, and I suggest that it(they) be sorted
out before proceeding further to function results and allocatable components:
(i) When a procedure is invoked, any allocated allocatable object that is
an actual argument associated with an INTENT(OUT) allocatable dummy argument
is deallocated; any allocated allocatable object that is a subobject of an
actual argument associated with an INTENT(OUT) dummy argument is deallocated.
(6.3.3.1).
To quote Metcalf, Reid and Cohen - "If the intent is OUT and the array is
allocated on entry, it becomes deallocated." Thus, subroutine kill in your
allocatable_dummy_1.f90 should give a runtime error for trying to deallocate
an already deallocated array.
Please find attached a patch to fix this and a revised version of
allocatable_dummy_1.f90. I suggest that this block of code be broken out
into a new function that can be referenced from gfc_conv_function_call and
trans-array.c(gfc_trans_deferred_array) from where it has been borrowed.
This function will be needed for allocatable components too.
This generates, for example:
if ((int4[0:] *) b.data != 0B)
{
{
void * * D.971;
D.971 = &b.data;
_gfortran_deallocate (D.971, 0B);
}
}
else
{
(void) 0;
}
kill (&b);
(ii) The second problem concerns the correct association of pointers and
allocatable arrays, where the actual argument is host or use associated
as well. I have not checked the F95 standard yet but F2003 requires that
the dummy argument take precedence. Please find attached an example of
what is or is not allowed.
Again, quoting Metcalf, Reid and Cohen, "In particular, this means that
no reference to the actual argument (for example through it being a
module variable) is permitted from the invoked procedure if the dummy
array is allocated or deallocated there."
I have enclosed a mutilation of an example that should apply to pointers.
MOVE_ALLOC would indeed be a use addition to the gfortran armoury - thanks
for the suggestion, Salvatore.
Cheers
Paul
-------------- next part --------------
A non-text attachment was scrubbed...
Name: actual.diff
Type: application/octet-stream
Size: 6377 bytes
Desc: actual.diff
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20060306/5647678f/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: allocatable_dummy_3.f90
Type: application/octet-stream
Size: 965 bytes
Desc: allocatable_dummy_3.f90
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20060306/5647678f/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Note12.2.8.f90
Type: application/octet-stream
Size: 712 bytes
Desc: Note12.2.8.f90
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20060306/5647678f/attachment-0002.obj>
More information about the Fortran
mailing list