Segmentation fault with "pack" intrinsic

I think I have found another compiler bug - it appears to generate wrong code.

The following code gives a run-time segfault, although I believe it to be correct. (It runs to completion when compiled with Intel, GNU, Sun/Oracle, NAG, Pathscale and open64 Fortran). The segfault appears internal to “pack”, and turning on -Mchkptr appears to diagnose an error with a compiler-generated array.

This occurs with pgf90 v 12.9 on linux x86_64 at any opti mization level.



program packtest
  integer, parameter :: n=36
  logical, dimension(n,2) :: mask_0
  logical, dimension(:), allocatable :: mask
  integer, dimension(:),allocatable :: rank, tmp

  integer :: nzero, k

  allocate(rank(n), tmp(n), mask(n))
  mask_0 = reshape(&
         [.TRUE.,.TRUE.,.TRUE., .FALSE.,.TRUE.,.TRUE.,.TRUE.,.TRUE.,.TRUE.,&
          .TRUE., .FALSE.,.TRUE.,.TRUE.,.TRUE.,.TRUE.,.TRUE.,.TRUE., .FALSE.,&
          .FALSE.,.TRUE.,.TRUE.,.TRUE.,.TRUE.,.TRUE.,.TRUE., .FALSE.,.TRUE.,&
          .TRUE.,.TRUE.,.TRUE.,.TRUE.,.TRUE., .FALSE.,.TRUE.,.TRUE.,.TRUE.,&
          .TRUE.,.TRUE.,.TRUE., .FALSE.,.TRUE.,.TRUE.,.TRUE.,.TRUE.,.TRUE.,&
          .TRUE., .FALSE.,.TRUE.,.TRUE.,.TRUE.,.TRUE.,.TRUE.,.TRUE., .FALSE.,&
          .FALSE.,.TRUE.,.TRUE.,.TRUE.,.TRUE.,.TRUE.,.TRUE., .FALSE.,.TRUE.,&
          .TRUE.,.TRUE.,.TRUE.,.TRUE.,.TRUE., .FALSE.,.TRUE.,.TRUE.,.TRUE.],[n,2])

  do k = 0,1
     write(*,*) k
     rank = 0
     mask = mask_0(:,k+1)
     nzero = count(mask)

     tmp(1:nzero)   = pack(rank, mask)
     tmp(nzero+1:n) = pack(rank, .not. mask)
     rank = tmp
  end do

  write(*,*) rank

end program packtest

Hi Keith,

This looks like the same issue first report HERE and logged as TPR#18937. The good news is that a fix will be available in 12.10 which will be available very soon.

  • Mat
% pgf90 pack.f90 -V12.9
% a.out
            0
Segmentation fault
% pgf90 pack.f90 -V12.10
% a.out
            0
            1
            0            0            0            0            0            0 
            0            0            0            0            0            0 
            0            0            0            0            0            0 
            0            0            0            0            0            0 
            0            0            0            0            0            0 
            0            0            0            0            0            0