This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [Patch, Fortran] PR56907 - do not 'pack' arrays passed to C_LOC
- From: Janus Weil <janus at gcc dot gnu dot org>
- To: Tobias Burnus <burnus at net-b dot de>
- Cc: gcc patches <gcc-patches at gcc dot gnu dot org>, gfortran <fortran at gcc dot gnu dot org>
- Date: Sat, 20 Apr 2013 13:44:04 +0200
- Subject: Re: [Patch, Fortran] PR56907 - do not 'pack' arrays passed to C_LOC
- References: <5165C8D0 dot 7020606 at net-b dot de> <CAKwh3qh=i0H4C7=3wavUvfkzA_FeUCaxiOctJ9n4821P_gLu1Q at mail dot gmail dot com> <5171B40C dot 8000901 at net-b dot de> <CAKwh3qh+AjpWfcq4cLbFRf=j3TdtUpmwTiZCMj6WFUk+EHL43w at mail dot gmail dot com> <517274F5 dot 4000500 at net-b dot de>
>>> 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).
>
> Well, the code in question is under:
>
> if (expr->value.function.isym->id == GFC_ISYM_C_LOC)
Ah, sure, I missed that.
Btw, wouldn't it make more sense to split up
'conv_isocbinding_function' into three separate functions, since there
isn't really any common code and one could directly call them in:
case GFC_ISYM_C_ASSOCIATED:
case GFC_ISYM_C_FUNLOC:
case GFC_ISYM_C_LOC:
conv_isocbinding_function (se, expr);
break;
Anyway, the patch is ok as is (or with this additional cleanup, if you prefer).
>> 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 ...
>> ?
>
> Definitely. I think there is also a PR about adding a
> gfc_is_simply_noncontiguous() or something like that. It has several uses:
> C_LOC, pointer-assignment to a contiguous pointer, removing some "if"s
> related to packing (as one knows that internal_pack will pack). And for
> compile-time simplification of the (unimplemented) Fortran 2008 function
> "is_contiguous".
Right: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45424
Cheers,
Janus