Complex array constructor leads to segfault

pgf95 compiles the following code:

program unpack1
  implicit none

  integer, parameter :: m = 8, n = 30, k = 6
  integer, dimension(m), parameter :: b = (/ 3, 4, 2, 2, 6, 6, 5, 2 /)

  integer, dimension(n) ::  &
       a = (/1,4,7,2,6,9,8,5,2,5,1,6,3,6,4,7,8,4,0,4,3,2,7,8,9,4,3,2,1,5/)
  integer, dimension(k,m) :: d
  integer :: j, i

  d = reshape((/ (a(sum(b(:j-1))+1:sum(b(:j))),  &
       (0, i = 1, k-b(j)), j = 1, m) /), (/ k, m /))

  do j = 1, k
     write (*, "(9i2)") d(j,:)
  end do
end program unpack1

However, I get a segmentation fault when I run the program regardless of the optimization level. The slightly modified program:

program unpack2
  implicit none

  integer, parameter :: m = 8, n = 30, k = 6
  integer, dimension(m), parameter :: b = (/ 3, 4, 2, 2, 6, 6, 5, 2 /)

  integer, dimension(n) ::  &
       a = (/1,4,7,2,6,9,8,5,2,5,1,6,3,6,4,7,8,4,0,4,3,2,7,8,9,4,3,2,1,5/)
  integer, dimension(k*m) :: c
  integer, dimension(k,m) :: d
  integer :: j, i

  do j = 1, m
     c((j-1)*k+1:j*k) = (/ a(sum(b(:j-1))+1:sum(b(:j))),  &
          (0, i = 1, k-b(j)) /)
  end do

  d = reshape(c, (/ k, m /))

  do j = 1, k
     write (*, "(9i2)") d(j,:)
  end do
end program unpack2

does run and produces the following output:

 1 2 5 5 6 4 8 1
 4 6 2 1 3 0 9 5
 7 9 0 0 6 4 4 0
 0 8 0 0 4 3 3 0
 0 0 0 0 7 2 2 0
 0 0 0 0 8 7 0 0

I think this output should also be produced by the first program. Am I right? If so, does the latest version of pgf95 work with this code?

I’m using pgf95 6.2-3 64-bit target on x86-64 Linux.

Hi rusteve,

I think this output should also be produced by the first program. Am I right? If so, does the latest version of pgf95 work with this code?

I believe you are correct and the problem does still occur in 7.0. I’ve sent this to our compiler team for investigation, reference TPR#4256.

Thank you for the report and the great examples,
Mat