"STAT=" specifier behavior in Fortran ALLOCATE statement

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

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.

$ 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.

$ 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.

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

-Mat

Behavior corrected with PGI 20.1