我正在测试PGI Fortran 19.10编译器。
当我运行名为segmentation fault
的文件时,用PGI编译后得到了test.f90
;而当我使用gfortran或ifort编译并运行时,我没有问题。
文件test.f90
:
MODULE modu
IMPLICIT NONE
! Format
type, abstract :: FormatFile
contains
procedure(File_open_file),nopass, deferred :: open_files
end type FormatFile
type, extends(FormatFile) :: FormatA
contains
procedure, nopass :: open_files => open_fileA
end type FormatA
! Type
type, abstract :: TypeFile
class(FormatFile), allocatable :: format
end type TypeFile
type, extends(TypeFile) :: TypeB
end type TypeB
! FileHandler
type, public :: FileHandler
private
class(TypeFile), allocatable :: type
contains
procedure, pass(fd), public :: open_file
end type FileHandler
abstract interface
subroutine File_open_file( fd )
import FileHandler
class(FileHandler), intent(inout) :: fd
end subroutine
end interface
CONTAINS
subroutine write_output()
IMPLICIT NONE
type(FileHandler) :: FileH
!-------------------------------------------------------------------------
print*, 'write_output: start.'
allocate(TypeB :: FileH%type)
allocate( FormatA :: FileH%type%format)
call FileH%open_file()
print*, 'write_output: end.'
end subroutine write_output
subroutine open_file( fd )
implicit none
class(FileHandler), intent(inout) :: fd
!-------------------------------------------------------------------------
print *, 'open_file: start'
call fd%type%format%open_files(fd)
print *, 'open_file: end'
end subroutine open_file
subroutine open_fileA( fd )
implicit none
class(FileHandler), intent(inout) :: fd
!-------------------------------------------------------------------------
print *, 'open_fileA: start'
!print*, 'job done'
print *, 'open_fileA: end'
end subroutine open_fileA
end module modu
PROGRAM main_prog
USE modu
print*, "Start main"
call write_output()
print*, "End main"
END PROGRAM main_prog
因此,命令pgfortran -c test.f90 && pgfortran -o main_test test.o && ./main_test
返回了我:
Start main
write_output: start.
open_file: start
Segmentation fault (core dumped)
使用gfortran或ifort可以正常运行。否则,我还会使用PGI编译器的选项-Mnollvm
测试此代码,并且会产生相同的分段错误。
当然,在这个简单的示例中,我可以删除中间对象TypeFile
,这可以消除分段错误问题;但我确实在更大的项目中需要它。
那么我想念什么吗?还是PGI编译器的错误?