http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37829
Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jvdelisle at gcc dot | |gnu.org Known to fail| | --- Comment #16 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2011-01-13 05:46:01 UTC --- >From c.l.f James Van Buskirk; Elusive bug PR37829 That bug bugs me so bad and it's hard to reproduce, but I found a trigger: C:\gfortran\clf\opengl2>type bug1.f90 module m3 use ISO_C_BINDING implicit none private public kill_C_PTR interface function kill_C_PTR() bind(C) import implicit none type(C_PTR) kill_C_PTR end function kill_C_PTR end interface public kill_C_FUNPTR interface function kill_C_FUNPTR() bind(C) import implicit none type(C_FUNPTR) kill_C_FUNPTR end function kill_C_FUNPTR end interface end module m3 module m1 use m3 end module m1 program X use m1 use ISO_C_BINDING implicit none type(C_PTR) cp type(C_FUNPTR) fp integer(C_INT),target :: i interface function fun() bind(C) use ISO_C_BINDING implicit none real(C_FLOAT) fun end function fun end interface cp = C_NULL_PTR cp = C_LOC(i) fp = C_NULL_FUNPTR fp = C_FUNLOC(fun) end program X function fun() bind(C) use ISO_C_BINDING implicit none real(C_FLOAT) fun fun = 1.0 end function fun function kill_C_PTR() bind(C) use ISO_C_BINDING implicit none type(C_PTR) kill_C_PTR integer(C_INT), pointer :: p allocate(p) kill_C_PTR = C_LOC(p) end function kill_C_PTR function kill_C_FUNPTR() bind(C) use ISO_C_BINDING implicit none type(C_FUNPTR) kill_C_FUNPTR interface function fun() bind(C) use ISO_C_BINDING implicit none real(C_FLOAT) fun end function fun end interface kill_C_FUNPTR = C_FUNLOC(fun) end function kill_C_FUNPTR C:\gfortran\clf\opengl2>gfortran bug1.f90 -obug1 bug1.f90:44.8: cp = C_NULL_PTR 1 Error: Can't convert TYPE(_gfortran_iso_c_binding_c_ptr) to TYPE(c_ptr) at (1) bug1.f90:45.8: cp = C_LOC(i) 1 Error: Can't convert TYPE(_gfortran_iso_c_binding_c_ptr) to TYPE(c_ptr) at (1) bug1.f90:46.8: fp = C_NULL_FUNPTR 1 Error: Can't convert TYPE(_gfortran_iso_c_binding_c_funptr) to TYPE(c_funptr) at (1) bug1.f90:47.8: fp = C_FUNLOC(fun) 1 Error: Can't convert TYPE(_gfortran_iso_c_binding_c_funptr) to TYPE(c_funptr) at (1) bug1.f90:63.16: kill_C_PTR = C_LOC(p) 1 Error: Can't convert TYPE(_gfortran_iso_c_binding_c_ptr) to TYPE(c_ptr) at (1) bug1.f90:77.19: kill_C_FUNPTR = C_FUNLOC(fun) 1 Error: Can't convert TYPE(_gfortran_iso_c_binding_c_funptr) to TYPE(c_funptr) at (1) It's the use of a function with result of TYPE(C_PTR) that kills C_PTR subsequently and similarly the function with a result of TYPE(C_FUNPTR) kills off C_FUNPTR. Abstract interfaces do the trick as well as interfaces to realized functions. Note that directly USEing module m3 in program X above isn't sufficient to trigger the bug: m3 needs to be USEd in intermediate module m1 which then is USEd in program X. It's hard to set this one off, but when you do, look out! Note that the last two failures occur in external functions that don't even USE module m3 or m1 directly or indirectly, yet they still fall victim once the compiler has come off the rails.