Fortran 2008 submodule & select type bug

For “nvfortran” (including version 22.9), there seems to be a bug when select type is used within a submodule. Here is a minimal example that is important for several programs and libraries including h5fortran.
This bug has been present I think since beginning of nvfortran Fortran 2008 support.

module amod

use, intrinsic :: iso_fortran_env

implicit none

interface
module subroutine sel(A)
CLASS(*), INTENT(INOUT) :: A
end subroutine sel
end interface


end module amod


submodule (amod) smod

implicit none

contains
module subroutine sel(A)
class(*), intent(inout) :: A

select type (A)
type is (real(real32))
 print *, 'real32'
type is (real(real64))
 print *, 'real64'
type is (integer(int32))
 print *, 'int32'
class default
 error stop 'unknown type'
end select

end subroutine sel

end submodule smod


program aaaa

use amod

implicit none

real(real32) :: x
real(real64) :: x64

call sel(x)
call sel(x64)

end program

compling with nvfortran gives errors:

/tmp/nvfortrangTv3eskus9U3F.o: In function `amod_sel_':
src.f90:25: undefined reference to `amod__smod_sel__f03_unl_poly_0____td2_'
src.f90:25: undefined reference to `amod__smod_sel__f03_unl_poly_0____td2_'
src.f90:25: undefined reference to `amod__smod_sel__f03_u

Note the more common “procedure” syntax in this example has a different but related error. Either of these syntaxes is legal Fortran 2008. This syntax below is more common I believe.

module amod

use, intrinsic :: iso_fortran_env

implicit none

interface
module subroutine sel(A)
CLASS(*), INTENT(INOUT) :: A
end subroutine sel
end interface


end module amod


submodule (amod) smod

implicit none

contains
module procedure sel

select type (A)
type is (real(real32))
 print *, 'real32'
type is (real(real64))
 print *, 'real64'
type is (integer(int32))
 print *, 'int32'
class default
 error stop 'unknown type'
end select

end procedure sel

end submodule smod


program aaaa

use amod

implicit none

real(real32) :: x
real(real64) :: x64

call sel(x)
call sel(x64)

end program
NVFORTRAN-S-0155-A SELECT TYPE selector without an associate-name must be a named variable  (y.f90: 24)
NVFORTRAN-S-0000-Internal compiler error. mk_id: invalid symbol table index       0  (y.f90: 25)
NVFORTRAN-S-0000-Internal compiler error. sym_of_ast: unexpected ast      76  (y.f90: 25)
NVFORTRAN-S-0000-Internal compiler error. mk_id: invalid symbol table index       0  (y.f90: 25)
NVFORTRAN-S-0000-Internal compiler error. mk_id: invalid symbol table index       0  (y.f90: 27)
NVFORTRAN-S-0000-Internal compiler error. sym_of_ast: unexpected ast      77  (y.f90: 27)
NVFORTRAN-S-0000-Internal compiler error. mk_id: invalid symbol table index       0  (y.f90: 29)
NVFORTRAN-S-0000-Internal compiler error. sym_of_ast: unexpected ast      77  (y.f90: 29)
NVFORTRAN-S-0000-Internal compiler error. mk_id: invalid symbol table index       0  (y.f90: 33)
NVFORTRAN-S-0000-Internal compiler error. mk_id: invalid symbol table index       0  (y.f90: 33)
NVFORTRAN-S-0000-Internal compiler error. mk_id: invalid symbol table index       0  (y.f90: 33)
NVFORTRAN-S-0000-Internal compiler error. mk_id: invalid symbol table index       0  (y.f90: 33)
NVFORTRAN-S-0000-Internal compiler error. mk_id: invalid symbol table index       0  (y.f90: 33)
NVFORTRAN-S-0000-Internal compiler error. mk_id: invalid symbol table index       0  (y.f90: 33)
  0 inform,   0 warnings,  14 severes, 0 fatal for sel

Thanks for the report mhirsch!

I was able to recreate both errors here, and have filed two issue reports. TPR#32551 for the undefined references error, and TPR#32552 for the ICE.

-Mat

1 Like

I have the same symptoms with nvfortran 22.11, so I think the bug wasn’t gotten to yet.