[Patch, Fortran] PR56907 - do not 'pack' arrays passed to C_LOC

Tobias Burnus burnus@net-b.de
Fri Apr 19 21:16:00 GMT 2013


Janus Weil:
> What I don't quite understand is:
> @@ -6317,8 +6317,13 @@ conv_isocbinding_function (gfc_se *se, gfc_expr *expr)
>       {
>         if (arg->expr->rank == 0)
>       gfc_conv_expr_reference (se, arg->expr);
> -      else
> +      else if (gfc_is_simply_contiguous (arg->expr, false))
>       gfc_conv_array_parameter (se, arg->expr, true, NULL, NULL, NULL);
> +      else
> +    {
> +      gfc_conv_expr_descriptor (se, arg->expr);
> +      se->expr = gfc_conv_descriptor_data_get (se->expr);
> +    }
>
>
> Why doesn't 'gfc_conv_array_parameter' handle this situation properly?

Well, it does: As it doesn't know whether the array is contiguous or not 
- it packs the array. That's what one usually wants.

However, for C_LOC one knows that the array is contiguous - the user 
promises this to the compiler - and, hence, no packing is needed.

> After all there is code like this inside:
>    no_pack = (...)
>                ||
>           gfc_is_simply_contiguous (expr, false));
> Wouldn't it be better to fix the logic in there, instead of avoiding
> to call it alltogether? This might also help in other situations ...

I don't know of any other situation where the *user* guarantees that the 
argument is contiguous while the compiler cannot check this. And even if 
the user lied to the compiler - doing no packing gives at least the 
address of the first element instead of the address of an immediately 
feed temporary array.

(Actually, there are other places in the compiler, where the user 
guarantees this: Pointer assignment to a "contiguous" pointer; there, 
the user promises that the target is contiguous. Maybe there are other 
spots as well. On the other hand, if the dummy argument has the 
CONTIGUOUS attribute, an automatic copy-in/out is required if it is not 
contiguous.)

Tobias

Tobias



More information about the Fortran mailing list