> cat main.c #include <errno.h> #include <string.h> #include "ISO_Fortran_binding.h" int main (int argc, char *argv[]) { int ret; int line; int my_errno; int i; CFI_CDESC_T(1) cdesc; CFI_rank_t rank = 1; int version = CFI_VERSION; CFI_attribute_t attribute = CFI_attribute_allocatable; CFI_type_t typ = CFI_type_double; CFI_index_t extents[rank]; CFI_index_t lower_bounds[rank]; CFI_index_t upper_bounds[rank]; size_t elem_len; // value doesn't matter void sub (CFI_cdesc_t *); for (i = 0; i < rank; i++) { extents[i] = 100; lower_bounds[i] = 1; upper_bounds[i] = 100; } ret = CFI_establish ((CFI_cdesc_t *)&cdesc, 0, attribute, typ, elem_len, rank, extents); if (ret != CFI_SUCCESS) { line = __LINE__; goto done; } ret = CFI_allocate ((CFI_cdesc_t *)&cdesc, lower_bounds, upper_bounds, elem_len); if (ret != CFI_SUCCESS) { line = __LINE__; goto done; } sub ((CFI_cdesc_t *) &cdesc); line = 0; done: if (line != 0) { asm ("hlt"); } return 0; } > cat sub.f90 subroutine sub (a) bind (c) use,intrinsic :: iso_c_binding real(C_double), allocatable :: a(:) do i = 1, size(a, 1) a(i) = i end do print *, a end subroutine sub > > ftn -c sub.f90 > cc main.c sub.o > ./a.out At line 7 of file sub.f90 (unit = 6, file = 'stdout') Internal Error: list_formatted_write(): Bad type It appears that the C descriptor, after being converted to a Fortran descriptor, has the wrong type information encoded. > cc --version gcc (GCC) 9.3.0 20200312 (Cray Inc.) Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > ftn --version GNU Fortran (GCC) 9.3.0 20200312 (Cray Inc.) Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Output from other compilers: > module swap PrgEnv-gnu PrgEnv-cray > ftn -c sub.f90 > cc main.c sub.o > ./a.out 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 51., 52., 53., 54., 55., 56., 57., 58., 59., 60., 61., 62., 63., 64., 65., 66., 67., 68., 69., 70., 71., 72., 73., 74., 75., 76., 77., 78., 79., 80., 81., 82., 83., 84., 85., 86., 87., 88., 89., 90., 91., 92., 93., 94., 95., 96., 97., 98., 99., 100. > module swap PrgEnv-cray PrgEnv-intel > ftn -c sub.f90 > cc main.c sub.o > ./a.out 1.00000000000000 2.00000000000000 3.00000000000000 4.00000000000000 5.00000000000000 6.00000000000000 7.00000000000000 8.00000000000000 9.00000000000000 10.0000000000000 11.0000000000000 12.0000000000000 13.0000000000000 14.0000000000000 15.0000000000000 16.0000000000000 17.0000000000000 18.0000000000000 19.0000000000000 20.0000000000000 21.0000000000000 22.0000000000000 23.0000000000000 24.0000000000000 25.0000000000000 26.0000000000000 27.0000000000000 28.0000000000000 29.0000000000000 30.0000000000000 31.0000000000000 32.0000000000000 33.0000000000000 34.0000000000000 35.0000000000000 36.0000000000000 37.0000000000000 38.0000000000000 39.0000000000000 40.0000000000000 41.0000000000000 42.0000000000000 43.0000000000000 44.0000000000000 45.0000000000000 46.0000000000000 47.0000000000000 48.0000000000000 49.0000000000000 50.0000000000000 51.0000000000000 52.0000000000000 53.0000000000000 54.0000000000000 55.0000000000000 56.0000000000000 57.0000000000000 58.0000000000000 59.0000000000000 60.0000000000000 61.0000000000000 62.0000000000000 63.0000000000000 64.0000000000000 65.0000000000000 66.0000000000000 67.0000000000000 68.0000000000000 69.0000000000000 70.0000000000000 71.0000000000000 72.0000000000000 73.0000000000000 74.0000000000000 75.0000000000000 76.0000000000000 77.0000000000000 78.0000000000000 79.0000000000000 80.0000000000000 81.0000000000000 82.0000000000000 83.0000000000000 84.0000000000000 85.0000000000000 86.0000000000000 87.0000000000000 88.0000000000000 89.0000000000000 90.0000000000000 91.0000000000000 92.0000000000000 93.0000000000000 94.0000000000000 95.0000000000000 96.0000000000000 97.0000000000000 98.0000000000000 99.0000000000000 100.000000000000
This seems fixed on trunk (GCC11) and gcc version 10.1.1 20200717 [revision r10-8504-g8e6c87b2baee] (GCC).
Confirmed with gcc version 10.2.0.