https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90539
--- Comment #25 from Martin Liška <marxin at gcc dot gnu.org> --- (In reply to Thomas Koenig from comment #22) > I've been trying out some things, and I cannot construct a failing > test case. > > A sane way to build such an interface would be > > cat tst.f90 > module x > use, intrinsic :: iso_c_binding, only : c_double > implicit none > interface > subroutine foo(a) bind(c) > import > real(kind=c_double) :: a(*) > end subroutine foo > end interface > private > public :: bar > > contains > subroutine bar(a) > real(kind=c_double), dimension(:) :: a > a = 42._c_double > call foo(a) > end subroutine bar > end module x > > program main > use, intrinsic :: iso_c_binding, only : c_double > use x > implicit none > real(kind=c_double), dimension(1) :: a > call bar(a) > end program main > $ cat foo.c > #include <stdio.h> > > void foo (double *a) > { > printf("%f\n", *a); > } > $ gfortran -flto -O tst.f90 foo.c > $ ./a.out > 42.000000 > > This works as expected. > > What I do not understand is (comment #17) > > (gdb) p debug(fsym) > || symbol: '_formal_107' > type spec : (REAL 8) > attributes: (VARIABLE DIMENSION DUMMY) > Array spec:(0 [0]) > > > This means that the dummy parameter has rank zero. How, then, > is it possible to pass a rank-1 argument to it? > > (gdb) p debug(expr) > nf90_put_var_1d_eightbytereal:values(FULL) (REAL 8) > > (gdb) p *expr->ref > $8 = { > type = REF_ARRAY, > u = { > ar = { > type = AR_FULL, > dimen = 1, > codimen = 0, > > Something very fishy going on here. > > Please look up the Fortran interface to the C function that is called, > nc_put_vara_double. > > Also, please break on gfc_conv_procedure_call for the call > in question and do > > $ call debug(sym) > $ p args > $ call debug(args->expr) > $ p args->next > $ call debug(args->next->expr) (gdb) call debug(sym) || symbol: 'nf_put_vara_double' type spec : (INTEGER 4) attributes: (PROCEDURE EXTERNAL-PROC IMPLICIT-SAVE EXTERNAL FUNCTION) result: nf_put_vara_double Formal arglist: _formal_103 _formal_104 _formal_105 _formal_106 _formal_107 (gdb) p args $4 = (gfc_actual_arglist *) 0x2a766f0 (gdb) call debug(args->expr) nf90_put_var_1d_eightbytereal:ncid (INTEGER 4) (gdb) p args->next $5 = (gfc_actual_arglist *) 0x2a72150 (gdb) call debug(args->next->expr) nf90_put_var_1d_eightbytereal:varid (INTEGER 4) (gdb) call debug(args->next->next->expr) nf90_put_var_1d_eightbytereal:localstart(FULL) (INTEGER 4) (gdb) call debug(args->next->next->next->expr) nf90_put_var_1d_eightbytereal:localcount(FULL) (INTEGER 4) (gdb) call debug(args->next->next->next->next->expr) nf90_put_var_1d_eightbytereal:values(FULL) (REAL 8) > > ... and so on, until args->...->next becomes a null pointer. > > I am starting do suspect that this is, in fact, another piece of SPEC > bugware where they made some sort of broken interface between C > and Fortran, which is exposed by my patch. That's likely :) Hope my remove gdb session helped. > > Hmpf...