pgfortran ICE when using type-bound operator from a module

The following code generates an internal compiler error with pgfortran 13.9:

module bound_op_mod

implicit none

type foo
   integer :: n
 contains
   procedure, pass(f1) :: sum_this => sum_foo
   generic, public :: operator(+) => sum_this
end type foo

contains

function sum_foo(f1, f2) result(new_f)
  class(foo), intent(in) :: f1, f2
  type(foo) :: new_f

  new_f = foo(f1%n + f2%n)

end function sum_foo

end module bound_op_mod

program test_bound_operator

use bound_op_mod, only: foo

implicit none

type(foo) :: f

f = foo(1) + foo(2)

print *, f

end program test_bound_operator

The error messages are:

PGF90-S-0000-Internal compiler error. mkexpr1: bad id 14 (pgi_internal_error.F90: 9)
PGF90-S-0000-Internal compiler error. sym_of_ast: unexpected ast 0 (pgi_internal_error.F90: 9)
PGF90-S-0155-Type bound procedure must be a module procedure or an external procedure with an explicit interface - (pgi_internal_error.F90: 9)
PGF90-S-0000-Internal compiler error. sym_of_ast: unexpected ast 0 (pgi_internal_error.F90: 9)

(“pgi_internal_error.F90” was the name of the file I put this test case in.)

On one machine with PGI 13.9, the compiler hangs after this point. On another machine with 13.7, it manages to error out without hanging. I have (much more complex) code that successfully uses type-bound operators with PGI 13.7, so it’s not at all clear to me what the issue is in this simple case.

Hi Sean Patrick Santos,

Thanks for the report. I’ve recreated the issue here and sent it on to engineering for further investigation (TPR#19990).

Here’s a work around until we can get the issue resolved.

module bound_op_mod 

implicit none 

type foo 
   integer :: n 
 contains 
   procedure, pass(f1) :: sum_this => sum_foo 
   generic, public :: operator(+) => sum_this 
end type foo 

contains 

function sum_foo(f1, f2) result(new_f) 
  class(foo), intent(in) :: f1, f2 
  type(foo) :: new_f 

  new_f = foo(f1%n + f2%n) 

end function sum_foo 

end module bound_op_mod

program test_bound_operator

use bound_op_mod, only: foo

implicit none

type(foo) :: f, f1, f2

f1 = foo(1)
f2 = foo(2)
f = f1 + f2
!f = foo(1) + foo(2)

print *, f

end program test_bound_operator

Best Regards,
Mat

TPR 19990 - UF: pgfortran ICE when using type-bound operator from a module

has been fixed in the current 14.6 release.

thanks,
dave