ICE for nested Array operations

Hi all,

I encounter an internal compiler error with the following test code:

subroutine test(field)

  real, dimension(*), intent(inout) :: field  !! Data (at least ndim1*ndim2*ndim3 Elements)

  integer, dimension(1:3) :: dims1, dims2
  integer :: npoints
  integer :: i

  do i=1,3
      field(1:npoints*dims2(i)) = pack(spread(reshape(field(1:npoints), dims1(3:1:-1)), i, dims2(i)), .true.)
  end do

end subroutine test

It is compiled with nvfortran (HPC SDK 23.3, nvfortran 23.3-0 64-bit target on x86-64 Linux -tp skylake-avx512) as nvfortran -c test.f90. This gives the following output:

NVFORTRAN-S-0000-Internal compiler error. mk_id: invalid symbol table index       0  (test.f90: 10)
NVFORTRAN-S-0000-Internal compiler error. lower_sptr: bad sptr       0  (test.f90: 13)
  0 inform,   0 warnings,   2 severes, 0 fatal for test

Regards,
Christian

Hi Christian,

Thanks for the report. This appears to be the same issue reported a few weeks ago having to using a reshape inside a spread intrinsic:

I’ve added your report to TPR #33446.

-Mat

Hi Mat,

I was investigating a workaround for this ICE when I found some further misbehavior of the numerical results. Consider this test case

program test

  implicit none

  integer, dimension(3) :: memdims
  integer, dimension(3) :: ksdims
  real(8), dimension(:), allocatable :: data
  real(8), dimension(:,:,:), allocatable :: data_reshaped
  integer :: Ngrid, Npoints
  integer :: i                                                                                
    
  memdims = (/1, 2, 4/)
  ksdims = (/4, 2, 3/)
  Npoints = product (memdims)
  Ngrid = product (ksdims)                                                                    
  allocate (data(Ngrid)) 
  allocate (data_reshaped(memdims(3), memdims(2), memdims(1)))                                
                                                                                              
  do i = 1, Ngrid
     data(i) = real (i)                                                                       
  end do 
        
  i = 3
  data_reshaped = reshape(data(1:Npoints), memdims(3:1:-1), order=(/3,2,1/))
  !!! In the original code, this is part of a loop where i appears as index
  data (1:Npoints * ksdims(i)) = pack(spread(data_reshaped, i, ksdims(i)), .true.) !!! BROKEN

  !!! If i is replaced by a constant 3, the gfortran results are reproduced
  !!!data (1:Npoints * ksdims(3)) = pack(spread(data_reshaped, 3, ksdims(3)), .true.) !!! OK

  !!! Put i on different positions. Apparently, the "dim" argument of spread causes trouble
  !!!data (1:Npoints * ksdims(3)) = pack(spread(data_reshaped, 3, ksdims(i)), .true.) !!! OK
  !!!data (1:Npoints * ksdims(3)) = pack(spread(data_reshaped, i, ksdims(3)), .true.) !!! BROKEN
  !!!data (1:Npoints * ksdims(i)) = pack(spread(data_reshaped, 3, ksdims(3)), .true.) !!! OK

  do i = 1, Ngrid
     print *, data(i)
  end do

  deallocate (data)
  deallocate (data_reshaped)
   
end program test

I have compiled this both with nvfortran and gfortran. The output of the nvfortran binary contains zeroes at the positions where the array is supposed to be extended. These zeroes are not generated by the gfortran binary. Interestingly, this does not happen when i is replaced by a numerical constant.

Maybe this example is helpful in fixing the problems with the array operations.

Regards,
Christian

Thanks Christian, Filed as TPR #33696.

Not sure if the two are related, but hopefully fixing the ICE will fix this one as well.