"STAT=" specifier behavior in Fortran ALLOCATE statement

Questions on using the PGI Compilers and Tools
Post Reply
tkt
Posts: 6
Joined: Aug 19 2004

"STAT=" specifier behavior in Fortran ALLOCATE statement

Post by tkt » Mon Oct 07, 2019 1:18 am

A program below is an example of re-allocation for array already allocated.

Code: Select all

program test
      integer, allocatable, dimension(:) :: foo
      integer ierr
      allocate(foo(100), STAT=ierr)
      write(*,*) 'status = ', ierr
      allocate(foo(100), STAT=ierr)   ! pgfortran stops at this point
      write(*,*) 'status = ', ierr
      write(*,*) 'well done!'
end program test 
Execution of the program is terminated at the allocation error point even though "STAT=" option is specified.

Code: Select all

$ pgf90 -V test2.f90
pgf90 19.7-0 LLVM 64-bit target on x86-64 Linux -tp sandybridge
PGI Compilers and Tools

$ a.out
 status =             0
0: ALLOCATE: array already allocated
Most compilers (intel, gfortran...) return an error code and continue to "execute" when attempting to allocate an array that was already allocated. Many users expect such a behavior if STAT= is present and the ALLOCATE statement fails.

Code: Select all

$ gfortran test2.f90
$ a.out
 status =            0
 status =         5014
 well done!
According to Fortran standard X3001-1-2009, if an error condition occurs during execution of an ALLOCATE statement that does not contain the STAT= specifier, execution of the program is terminated. However, the behavior when STAT= is specified is not explicitly defined. It may be implementation dependent.

But I hope it will be the same as other compilers.

mkcolg
Posts: 8067
Joined: Jun 30 2004

Re: "STAT=" specifier behavior in Fortran ALLOCATE statement

Post by mkcolg » Mon Oct 07, 2019 8:14 am

Thanks tkt. I added a problem report (TPR#27724) and sent it our engineers for further review.

-Mat

Post Reply