PGI 12.2 bug: array with variable dimension in main program

Here is a cut down version of the example posted in https://forums.developer.nvidia.com/t/runtime-error/132805/1

program ILLEGAL
implicit none
integer n,m,nm,i
real ,dimension(nm) :: V

n=2
m=0
nm=2*n-2-m+1
do i=1,nm
   V(i)=0
end do
end program ILLEGAL

The array V is declared with a dimension that is not a constant; the extent nm is not even defined. PGI 12.2 on Windows (32- or 64-bit) happily compiles and links the program with no error message. If the -C option is used, a run-time subscript error occurs. Otherwise, the program crashes after an access error occurs.

The program is illegal and compilation should fail. For the same test program, GFortran 4.5 says

real ,dimension(nm) :: V
                1
Error: Variable 'nm' cannot appear in the expression at (1)
kgupta.f90:4.24:

real ,dimension(nm) :: V
                        1
Error: The module or main program array 'v' at (1) must have constant shape

Thanks mecej4. I have send a report (TPR#18513) to our compiler engineers for further investigation.

  • Mat

This has been fixed as of the 13.9 release.

thanks,
dave