public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* Bug 104404 - Incorrect CFI_cdesc_t "type" member for assumed-type, assumed-rank complex dummy arguments
@ 2022-02-06  3:38 Damian Rouson
  2022-02-06  8:48 ` Paul Richard Thomas
  0 siblings, 1 reply; 3+ messages in thread
From: Damian Rouson @ 2022-02-06  3:38 UTC (permalink / raw)
  To: fortran

For an assumed-type, assumed-rank complex dummy argument in a C interface,
gfortran 11.2.0 passes a CFI_cdesc_t object with a "type" member that does
not match the corresponding CFI_type_float_Complex and
CFI_type_double_Complex values. In the case of a complex(c_float_complex)
argument, the passed "type" member corresponds to CFI_type_double_Complex.
For a complex(c_double_complex) argument, the "type" member has a value
that I don't recognize.  Does anyone know whether this has been fixed on
the 12 branch?

% cat c_descriptor.c
#include <stdio.h>
#include <ISO_Fortran_binding.h>

void c_descriptor(CFI_cdesc_t* c)
{
  printf("a_desc->type = %d \n", c->type);
  printf("a_desc->elem_len = %d \n", c->elem_len);
  printf("CFI_type_float_Complex = %d \n", CFI_type_float_Complex);
  printf("CFI_type_double_Complex = %d \n", CFI_type_double_Complex);
}

% cat c_descriptor.c
#include <stdio.h>
#include <ISO_Fortran_binding.h>

void c_descriptor(CFI_cdesc_t* c)
{
  printf("a_desc->type = %d \n", c->type);
  printf("a_desc->elem_len = %d \n", c->elem_len);
  printf("CFI_type_float_Complex = %d \n", CFI_type_float_Complex);
  printf("CFI_type_double_Complex = %d \n", CFI_type_double_Complex);
}
(base) rouson@CLaSS adhoc % cat assumed-type.f90
module c_descriptor_m
  implicit none
contains
  module subroutine print_type_info(a)
    type(*), intent(inout), contiguous, target :: a(..)

    interface
      subroutine c_descriptor(a) bind(C)
        implicit none
        type(*) a(..)
      end subroutine
    end interface

    call c_descriptor(a)

  end subroutine
end module

  use c_descriptor_m
  use iso_c_binding
  implicit none

  complex(c_float_complex) :: z_float = (0._c_float, 0._c_float)
  complex(c_double_complex):: z_double = (0._c_double, 0._c_double)

  print*, "-----  complex(c_float_complex) --------"
  call print_type_info(z_float)
  print*, "-----  complex(c_double_complex) -------"
  call print_type_info(z_double)
end

 % gfortran c_descriptor.c assumed-type.f90

% ./a.out
 -----  complex(c_float_complex) --------
a_desc->type = 2052
a_desc->elem_len = 8
CFI_type_float_Complex = 1028
CFI_type_double_Complex = 2052
 -----  complex(c_double_complex) -------
a_desc->type = 4100
a_desc->elem_len = 16
CFI_type_float_Complex = 1028
CFI_type_double_Complex = 2052

% gfortran --version
GNU Fortran (Homebrew GCC 11.2.0_3) 11.2.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-06 12:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-06  3:38 Bug 104404 - Incorrect CFI_cdesc_t "type" member for assumed-type, assumed-rank complex dummy arguments Damian Rouson
2022-02-06  8:48 ` Paul Richard Thomas
2022-02-06 12:11   ` Damian Rouson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).