https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117303
Bug ID: 117303 Summary: Link-time optimization optimizes away subroutine referred to via C_FUNLOC Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: chilikin.k at gmail dot com Target Milestone: --- Created attachment 59440 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59440&action=edit test.f90 With gfortran 14.2.0, the following program: $ cat test.f90 MODULE M1 USE, INTRINSIC :: ISO_C_BINDING TYPE T TYPE(C_FUNPTR) FUNPTR END TYPE TYPE(T), POINTER :: T_POINTER CONTAINS SUBROUTINE SET_FUNPTR(F) TYPE(C_FUNPTR), INTENT(IN) :: F T_POINTER%FUNPTR = F END SUBROUTINE SUBROUTINE S1() BIND(C) END SUBROUTINE END MODULE PROGRAM TEST USE M1 ALLOCATE(T_POINTER) CALL SET_FUNPTR(C_FUNLOC(S1)) PRINT *, T_POINTER%FUNPTR END PROGRAM works if it is compiled without link-time optimization: $ gfortran -O1 -o test test.f90 $ ./test 4198811 but with link-time optimization, there is a linker error: $ gfortran -O1 -flto -o test test.f90 ld: /tmp/ccL2ip3g.ltrans0.ltrans.o: in function `MAIN__': <artificial>:(.text+0x21): undefined reference to `s1' collect2: error: ld returned 1 exit status