[Fortran] Help with intrinsic function returning array
Mikael Morin
mikael.morin@sfr.fr
Tue May 17 19:47:00 GMT 2016
Le 17/05/2016 05:30, Alessandro Fanfarillo a écrit :
> Hi,
>
> actually I've already tried that way but the size of the array
> returned by the function cannot be computed by the compiler. The
> number of failed images is an information contained in OpenCoarrays
> (which is an external library).
>
> Here is an example:
>
> program fail
> integer, allocatable :: failed(:)
>
> failed = failed_images()
>
> end program
>
> In this case I expect to see the assignment translated into something like:
>
> failed.data = _gfortran_caf_failed_images(&size,0B,0B);
> failed.offset = -1;
> failed.dim[0].lbound = 1;
> failed.dim[0].ubound = size;
>
Well, what I was telling was aiming at producing something more like that:
_gfortran_caf_failed_images(&failed);
It's probably doable that way, but there might be some problems indeed
with the scalarizer. Most existing intrinsics functions calling the
library can have their result shape inferred before the call.
Now, to do it your way:
As failed_images is a function, you are supposed to produce an
expression that gfc_trans_assignment will use. You can't directly assign
to the lhs, as there may not be an lhs to assign to.
Think of the cases:
variable = (/ some_data, failed_images(), some_other_data /)
variable = some_function(failed_images())
the expression is your temporary descriptor, and it should be used after
it has been initialized by your code.
So set se->expr to parm (the array descriptor), and add all your code
(the result of gfc_finish_block) to se->pre.
That should be mostly it, but I guess the devil will be in the details.
Mikael
More information about the Fortran
mailing list