https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125383

            Bug ID: 125383
           Summary: Optional dummy procedure called from contained
                    subprogram results in linking error
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ripero84 at gmail dot com
  Target Milestone: ---

Compilation of the following file

===========

module m
  implicit none

contains

  subroutine work(parg)
    interface
      subroutine subint
      end subroutine
    end interface
    procedure(subint), optional :: parg

    call setup

  contains

    subroutine setup
      if (present(parg)) call parg
    end subroutine setup

  end subroutine work

  subroutine sub0
  end subroutine sub0

end module m

program p
  use m
  implicit none

  call work(parg=sub0)

end program p

===========

using gfortran 16.1.0 leads to a linking error:

$ gfortran p.f90 -o p
/usr/bin/ld: /tmp/cc8p8UEW.o: in function `setup.0':
p.f90:(.text+0x24): undefined reference to `parg_'
collect2: error: ld returned 1 exit status

This suggests an issue with the generated object code. The error appears if an
optional dummy procedure is called from within a contained subprogram. If the
optional dummy procedure is called also from the host subroutine, or if it is
passed to the contained subroutine as an argument, the linking error
disappears.

While the error happens in the linking stage, I think the error is not related
to the linker, since the same linker will work for other versions of the
compiler.

The issue also affects the current (as of today) gcc-14 and gcc-15 branches.

This issue was not present in any previous 14.x and 15.x releases, so it looks
like a regression.

I have not bisected from the source code when the issue was introduced, but
based on the Debian changelog and on the Debian package versions with and
without the problem it looks like the regressions would have been introduced in
gcc-14 and gcc-15 at some point between early September and late October 2025.

Reply via email to