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

            Bug ID: 104404
           Summary: Incorrect CFI_cdesc_t "type" member for assumed-type,
                    assumed-rank complex dummy arguments
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: damian at archaeologic dot codes
  Target Milestone: ---

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. Ian the case of a complex(c_float_complex) argument, 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
  • [Bug fortran/104404] New: In... damian at archaeologic dot codes via Gcc-bugs

Reply via email to