On Thu, May 9, 2019 at 12:31 AM Thomas Koenig <tkoe...@netcologne.de> wrote: > > Hello world, > > the attached patch fixes PR 90351 (not all prototypes were written > to standard output with -fc-prototypes) and introduces new > functionality to also write C prototypes for external functions, > at the same time discouraging their use (because BIND(C) is really > the better, standard-conforming and portable way). While looking > at the code, I also noticed that COMPLEX was not handled before, > so I added that, too. > > Example: > > $ cat c.f90 > integer function r(i) > end > > subroutine foo(a,b,c) > character*(*) a > real b > complex c > end > > character*(*) function x(r, c1,c2) > real r > character*(*) c1,c2 > end > $ gfortran -fsyntax-only -fc-prototypes-external c.f90 > /* Prototypes for external procedures generated from c.f90 > by GNU Fortran (GCC) 10.0.0 20190427 (experimental). > > Use of this interface is dicsouraged, consider using the > BIND(C) feature of standard Fortran instead. */ > > int r_ (int *i); > void foo_ (char *a, float *b, float complex *c, size_t a_len); > void x_ (char *result_x, size_t result_x_len, float *r, char *c1, char > *c2, size_t c1_len, size_t c2_len); > > I'd like to commit this to trunk and to gcc-9, to help users of > old-fashioned Lapack bindings, such as R, with their transition > to something that does not violate gfortran's ABI. > > Tested with "make dvi" and "make info". Otherwise, since these flags > are not tested in the testsuite (maybe they should be, I just don't > know how), regression test passed. > > OK? > > 2019-05-08 Thomas Koenig <tkoe...@gcc.gnu.org> > > PR fortran/90351 > PR fortran/90329 > * gfortran.dg/dump-parse-tree.c: Include version.h. > (gfc_dump_external_c_prototypes): New function. > (get_c_type_name): Select "char" as a name for a simple char. > Adjust to handling external functions. Also handle complex. > (write_decl): Add argument bind_c. Adjust for dumping of external > procedures. > (write_proc): Likewise. > (write_interop_decl): Add bind_c argument to call of write_proc. > * gfortran.h: Add prototype for gfc_dump_external_c_prototypes. > * lang.opt: Add -fc-prototypes-external flag. > * parse.c (gfc_parse_file): Move dumping of BIND(C) prototypes. > Call gfc_dump_external_c_prototypes if option is set. > * invoke.texi: Document -fc-prototypes-external. >
Thanks for this. I committed as obvious r271075 Index: ChangeLog =================================================================== --- ChangeLog (revision 271074) +++ ChangeLog (working copy) @@ -28,7 +28,7 @@ PR fortran/90351 PR fortran/90329 - * gfortran.dg/dump-parse-tree.c: Include version.h. + * dump-parse-tree.c: Include version.h. (gfc_dump_external_c_prototypes): New function. (get_c_type_name): Select "char" as a name for a simple char. Adjust to handling external functions. Also handle complex. -- Janne Blomqvist