https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92123

--- Comment #6 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Some side remarks:

(In reply to Jakub Jelinek from comment #5)
> The type used on the C side is:
This type is described in the Fortran standard; for Fortran 2018, it is
described in "18.5.3  The CFI_cdesc_t structure type" on page 481, cf.
https://j3-fortran.org/doc/year/18/18-007r1.pdf

That's defined on the gfortran side in libgfortran/ISO_Fortran_binding.h

> typedef struct CFI_cdesc_t
>  {
>     void *base_addr;
>     size_t elem_len;
…

> where void * and size_t are 64-bit on LP64 and 32-bit on ILP32,
> CFI_rank_t/CFI_attribute_t are 8-bit and CFI_type_t is 16-bit, while for
>     integer(c_int), allocatable, intent(out) :: dat(..)
…
> seems to assume dat type is a structure containing pointer sized data,
> array index offset, and dtype, which has size_t elem_len, int version, 8-bit
> rank, type and 16-bit attribute, so the Fortran FE assumption is there is
> extra 64-bit (or 32-bit) offset and type/attribute are swapped and have
> different types.

The conversion between gfortran's internal array descriptor and the one use
with C binding ("CFI_") is done in libgfortran/runtime/ISO_Fortran_binding.c
via cfi_desc_to_gfc_desc and gfc_desc_to_cfi_desc; this function is called from
the Fortran side.  (When calling a bind(C) function or for implementing in
Fortran a bind(C) function.)

The C side calls CFI_establish for a likewise purpose (same file).

Reply via email to