[Bug fortran/107375] New: CFI_cdesc_t incorrectly reports non-interoperable C structure as such

jeff.science at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Oct 24 11:25:02 GMT 2022


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

            Bug ID: 107375
           Summary: CFI_cdesc_t incorrectly reports non-interoperable C
                    structure as such
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jeff.science at gmail dot com
  Target Milestone: ---

Interoperable C structs are not permitted to contain allocatable members, among
other things.

The compiler should report that types containing allocatable members are
CFI_type_other, not CFI_type_struct.

I was not sure if the Fortran code was illegal or if the CFI_cdesc_t was
populated incorrectly, but another member of WG5 said it was the latter.


% gcc-12 -g -std=c11 -c foo.c -o foo.o
% gfortran-12 -g -std=f2018 class.F90 foo.o -o class.x
% ./class.x
CFI_cdesc_t.type      = interoperable C structure


==> foo.c <==
#include <stdio.h>
#include <stdlib.h>
#include "ISO_Fortran_binding.h"

char * get_type(CFI_type_t t)
{
    switch(t) {
        case CFI_type_cptr   : return "void *";                    break;
        case CFI_type_struct : return "interoperable C structure"; break;
        case CFI_type_other  : return "Not otherwise specified";   break;
        default              : abort();
    }
}

void foo(CFI_cdesc_t * d)
{
    printf("CFI_cdesc_t.type      = %s\n",  get_type(d->type));
}

==> class.F90 <==
module m

    type :: t
        integer :: i
        double precision :: d
        integer :: j(10)
        real :: r(100)
        real, allocatable :: z(:)
    end type t

    interface
        subroutine foo(t) bind(C)
            implicit none
            type(*), dimension(..) :: t
        end subroutine foo
    end interface

end module m

program main
    use m
    implicit none
    type(t) :: x
    call foo(x)
end program main


% gfortran-12 -v
Using built-in specs.
COLLECT_GCC=gfortran-12
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/12.2.0/bin/../libexec/gcc/aarch64-apple-darwin21/12/lto-wrapper
Target: aarch64-apple-darwin21
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc
--libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls
--enable-checking=release --with-gcc-major-version-only
--enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-12
--with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr
--with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl
--with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 12.2.0'
--with-bugurl=https://github.com/Homebrew/homebrew-core/issues
--with-system-zlib --build=aarch64-apple-darwin21
--with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Homebrew GCC 12.2.0)


More information about the Gcc-bugs mailing list