The code below compiles correctly, but produces a segmentation fault when run. The problem seems to be the abstract interface with assumed shape arrays: sub
fails, but sub2
works. Other compilers (gfortran, ifort, nagfor) work as expected.
nvfortran 23.1-0 64-bit target on x86-64 Linux -tp skylake-avx512
NVIDIA Compilers and Tools
Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
module mymod
use, intrinsic :: iso_fortran_env, only: real64
implicit none
private
public :: mysub, mysub2
abstract interface
subroutine mysub(A, B)
import :: real64
complex(kind=real64), intent(in) :: A(:,:)
complex(kind=real64), intent(out) :: B(:,:)
end subroutine mysub
subroutine mysub2(A, B, n)
import :: real64
integer, intent(in) :: n
complex(kind=real64), intent(in) :: A(n,n)
complex(kind=real64), intent(out) :: B(n,n)
end subroutine mysub2
end interface
end module mymod
subroutine sub(A, B)
use, intrinsic :: iso_fortran_env, only: real64
implicit none
complex(kind=real64), intent(in) :: A(:,:)
complex(kind=real64), intent(out) :: B(:,:)
B = A
end subroutine sub
subroutine sub2(A, B, n)
use, intrinsic :: iso_fortran_env, only: real64
implicit none
integer, intent(in) :: n
complex(kind=real64), intent(in) :: A(n,n)
complex(kind=real64), intent(out) :: B(n,n)
B = A
end subroutine sub2
program prog
use, intrinsic :: iso_fortran_env, only: real64
use mymod, only: mysub, mysub2
implicit none
complex(kind=real64) :: A(3,3), B(3,3)
procedure(mysub) :: sub
procedure(mysub2) :: sub2
A(:,:) = (1.0_real64, 2.0_real64)
B(:,:) = (0.0_real64, 0.0_real64)
! "sub" fails, but "sub2" works!
call sub(A, B)
!call sub2(A, B, 3)
write(6,*) B
end program prog