[Bug fortran/126485] New: Regression caused by r16-8455 / `64e03b96dfe`: Fortran: fix resolution of generic interface with TYPE(C_PTR) [PR66973]

henri at henrimenke dot de via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126485

            Bug ID: 126485
           Summary: Regression caused by r16-8455 / `64e03b96dfe`:
                    Fortran: fix resolution of generic interface with
                    TYPE(C_PTR) [PR66973]
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: henri at henrimenke dot de
  Target Milestone: ---

Created attachment 65169
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65169&action=edit
Minimal (probably insufficient) patch

The reproducer needs two files:


! mod_a.f90
module mod_a
  use iso_c_binding
  implicit none
end module mod_a

! bug.f90
subroutine s1(x)
  use mod_a          ! C_LOC reached indirectly, via a .mod
  real, target :: x
  call foo(c_loc(x)) ! first call: interface is synthesised here
end subroutine s1

subroutine s2(y)
  use mod_a
  real, target :: y
  call foo(c_loc(y)) ! second call: checked against it -> bogus error
end subroutine s2


Compiling the two gives a bogus error about a dummy argument '_formal_0' that
doesn't exist. The same code compiled correctly with GCC 15.1. Since PR66973
was backported to GCC 15, I think GCC 15.2 is affected as well.


$ gfortran --version
GNU Fortran (GCC) 16.1.0
[...]
$ gfortran -c mod_a.f90 
$ gfortran -c bug.f90 
bug.f90:10:11:

   10 |   call foo(c_loc(y)) ! second call: checked against it -> bogus error
      |           1
Error: ISO_C_BINDING function actual argument at (1) requires dummy argument
‘_formal_0’ to have a matching type from ISO_C_BINDING
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.