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

            Bug ID: 122641
           Summary: ICE with pointer derived type result of a deferred
                    procedure pointer component
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: N.T.Taylor at exeter dot ac.uk
  Target Milestone: ---

Created attachment 62763
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62763&action=edit
Reduced test case source code

I get an internal compiler error for the attached source. Cannot find a
workaround for it yet.


Versions tested on (GCC and system):
- GNU Fortran (Homebrew GCC 15.2.0) 15.2.0 - MacOS 15.6.1
- GNU Fortran (Ubuntu 14.2.0-4ubunit2~24.04) 14.2.0
- GNU Fortran (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0


Command line that caused the error:
gfortran test_error.f90


Error message during compilation:
test_error.f90:29:33:

   29 |     ptr => this%get_partial(grad)
      |                                 1
internal compiler error: in fold_convert_loc, at fold-const.cc:2633
0x11c23082a1c9 __libc_start_call_main
        ../sysdeps/nptl/libc_start_call_main.h:58
0x11c23082a28a __libc_start_main_impl
        ../csu/libc-start.c:360
Please submit a full bug report, with preprocessed source (by using
-freport-bug).


Options given when gcc was configured/built:
- For MacOS, built using `brew install gcc`
- For Ubuntu, built using `deb gfortran-14`


Example code that encounters the error:
- Module and program can be in the same or a separate file for the error to
occur
- For my report, I have put it all in one file called `test_error.f90`
- File also attached



module test_error
  implicit none

  type :: array_type
     procedure(get_partial_ptr), pass(this), pointer :: get_partial => null()
   contains
     procedure, pass(this) :: grad_reverse
  end type array_type

  interface
     module function get_partial_ptr(this, upstream_grad) result(output)
       class(array_type), intent(inout) :: this
       type(array_type), intent(in) :: upstream_grad
       type(array_type), pointer :: output
     end function get_partial_ptr
  end interface

contains

  function grad_reverse(this, grad) result(output)
    implicit none
    class(array_type), intent(inout) :: this
    type(array_type), intent(in) :: grad
    type(array_type) :: output

    type(array_type), pointer :: ptr

    ! Example implementation of getting the partial derivative
    ptr => this%get_partial(grad)
    output = ptr

  end function grad_reverse

end module test_error

program test
  use test_error
  implicit none

  type(array_type) :: a, b, c

  ! Example usage
  c = a%grad_reverse(b)

end program test

Reply via email to