Reported by Angelo Graziosi at http://gcc.gnu.org/ml/fortran/2013-04/msg00210.html Using in file1: module m ... type t type(c_funptr) :: funptr end type and in file2: use iso_c_binding, ONLY: c_funloc use m type(t) :: x ... x%funptr = c_funloc(proc) fails with: Error: Can't convert TYPE(c_funptr) to INTEGER(4) at (1) The problem is that the .mod file only contains: win32_types.mod:5 'C_funptr' '__iso_c_binding' '' 1 ((DERIVED UNKNOWN-INTENT while the symtree is searched for "c_funptr". Workaround: Editing the .mod file and changing C_funptr to c_funptr.
On x86_64-apple-darwin13, I get with gfortran 4.8.2 [Book15] f90/bug% gfortran pr57048.f90 [Book15] f90/bug% grep funptr m.mod (('c_funptr' '__iso_c_binding' 2) ('t' 'm' 3)) (2 'C_funptr' '__iso_c_binding' '' 1 ((DERIVED UNKNOWN-INTENT DERIVED 2 0 1 1 UNKNOWN ()) 0 0 () () 0 ((4 '__c_funptr_c_address' ( (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 ((5 'funptr' (DERIVED 2 0 0 0 7 'c_funptr' '__iso_c_binding' '' 1 ((PROCEDURE UNKNOWN-INTENT ('C_funptr' 0 2 'T' 0 3 '__iso_c_binding' 0 6 'c_funptr' 0 7 'm' 0 8 't' What is setting the capital C and why?
This fixes this case; However, it is not free of regressions. diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c index adc34dd..24ceaea 100644 --- a/gcc/fortran/trans-types.c +++ b/gcc/fortran/trans-types.c @@ -2366,8 +2366,6 @@ gfc_get_derived_type (gfc_symbol * derived) else derived->backend_decl = pfunc_type_node; - derived->ts.kind = gfc_index_integer_kind; - derived->ts.type = BT_INTEGER; /* Set the f90_type to BT_VOID as a way to recognize something of type BT_INTEGER that needs to fit a void * for the purpose of the iso_c_binding derived types. */
Created attachment 31956 [details] Bigger patch (doesn't work better :-/ ) And this is how far I got before giving up.
GCC 4.9.0 has been released
GCC 4.9.1 has been released.
GCC 4.9.2 has been released.
GCC 4.9.3 has been released.
GCC 4.9 branch is being closed
GCC 6 branch is being closed
Here's something that appears to work. Looks like a hack, swims like a hack, and quacks like a hack... Index: interface.c =================================================================== --- interface.c (Revision 268104) +++ interface.c (Arbeitskopie) @@ -692,6 +692,15 @@ if (ts1->type == BT_VOID || ts2->type == BT_VOID) return true; + /* Special case for our C interop types. There should be a better + way of doing this... */ + + if (((ts1->type == BT_INTEGER && ts2->type == BT_DERIVED) + || (ts1->type == BT_DERIVED && ts2->type == BT_INTEGER)) + && ts1->u.derived && ts2->u.derived + && ts1->u.derived == ts2->u.derived) + return true; + /* The _data component is not always present, therefore check for its presence before assuming, that its derived->attr is available. When the _data component is not present, then nevertheless the
... and even passes regression-testing. Well, let's see.
Author: tkoenig Date: Tue Jan 29 22:40:26 2019 New Revision: 268372 URL: https://gcc.gnu.org/viewcvs?rev=268372&root=gcc&view=rev Log: 2019-01-29 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/57048 * interface.c (gfc_compare_types): If a derived type and an integer both have a derived type, and they are identical, this is a C binding type and compares equal. 2019-01-29 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/57048 * gfortran.dg/c_funptr_1.f90: New file. * gfortran.dg/c_funptr_1_mod.f90: New file. Added: trunk/gcc/testsuite/gfortran.dg/c_funptr_1.f90 trunk/gcc/testsuite/gfortran.dg/c_funptr_1_mod.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/interface.c trunk/gcc/testsuite/ChangeLog
Author: tkoenig Date: Sat Feb 2 16:35:47 2019 New Revision: 268476 URL: https://gcc.gnu.org/viewcvs?rev=268476&root=gcc&view=rev Log: 2019-02-02 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/57048 Backport from trunk * interface.c (gfc_compare_types): If a derived type and an integer both have a derived type, and they are identical, this is a C binding type and compares equal. 2019-02-02 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/57048 Backport from trunk * gfortran.dg/c_funptr_1.f90: New file. * gfortran.dg/c_funptr_1_mod.f90: New file. Added: branches/gcc-8-branch/gcc/testsuite/gfortran.dg/c_funptr_1.f90 branches/gcc-8-branch/gcc/testsuite/gfortran.dg/c_funptr_1_mod.f90 Modified: branches/gcc-8-branch/gcc/fortran/ChangeLog branches/gcc-8-branch/gcc/fortran/interface.c branches/gcc-8-branch/gcc/testsuite/ChangeLog
Author: tkoenig Date: Sat Feb 2 16:57:39 2019 New Revision: 268478 URL: https://gcc.gnu.org/viewcvs?rev=268478&root=gcc&view=rev Log: 2019-02-02 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/57048 Backport from trunk * interface.c (gfc_compare_types): If a derived type and an integer both have a derived type, and they are identical, this is a C binding type and compares equal. 2019-02-02 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/57048 Backport from trunk * gfortran.dg/c_funptr_1.f90: New file. * gfortran.dg/c_funptr_1_mod.f90: New file. Added: branches/gcc-7-branch/gcc/testsuite/gfortran.dg/c_funptr_1.f90 branches/gcc-7-branch/gcc/testsuite/gfortran.dg/c_funptr_1_mod.f90 Modified: branches/gcc-7-branch/gcc/fortran/ChangeLog branches/gcc-7-branch/gcc/fortran/interface.c branches/gcc-7-branch/gcc/testsuite/ChangeLog
Fixed on all open branches, closing.