Hi Steve,
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.
I don't understand this sentence. How can an INTEGER have a
derived type?
ISO C handling is a bit of a mess. Of course.
The original tree has
symtree: 'C_funptr' || symbol: 'c_funptr'
type spec : (DERIVED c_funptr C_INTEROP ISO_C)
attributes: (DERIVED BIND(C) USE-ASSOC(__iso_c_binding))
components:
(c_address (INTEGER 8 C_INTEROP) () PRIVATE)
and we somehow later lose the derived type stuff and use a naked
integer. The problem appears to be that the module is written out
when that conversion has not yet happened.
So, the C_funptr (capitalized because it is a derived type) is
written to the module file, and later compared to c_funptr upon
module reading. Hilarity ensues, and we cannot use a C function
pointer from a module, the topic of the PR.
2019-01-28 Thomas Koenig <tkoe...@gcc.gnu.org>
PR fortran/57048
* gfortran.dg/c_funptr_1.f90: New file.
* gfortran.dg/c_funptr_1_mod.f90: New file.
Index: interface.c
===================================================================
--- interface.c (Revision 268104)
+++ interface.c (Arbeitskopie)
@@ -692,6 +692,15 @@ gfc_compare_types (gfc_typespec *ts1, gfc_typespec
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;
If the above is a test for ISO C binding, shouldn't the test
also check (ts1->is_c_interop || ts1->is_iso_c) and similar
for ts2?
Unfortunately, these are both set to zero.
Yep, this is a rather messy fix to a messy situation. I think the
C interop stuff could do with a thorough redesign, but that's
not going to happen for gcc 9.
So, I think this is about the best we can do - at least it gets the
bug fixed. If you want me to put in a FIXME, I'll gladly do this.
Regards
Thomas