This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


>> 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.

Ok, I see. Then the patch is certainly ok. (The fact that
conv_isocbinding_function is used also for C_ASSOCIATED and C_FUNLOC
is no problem either, I guess).

However, if calling C_LOC on a non-contiguous array is invalid,
shouldn't one add a check for cases like

  integer, dimension(1:5,1:5), target :: zzz
  type(c_ptr) :: ptr
  ptr = c_loc (zzz(4:,4:))

where the compiler can easily tell that the argument is not contiguous ... ?

Cheers,
Janus


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]