Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
37 Views

-check bounds fails with pointers on arrays

Jump to solution

This small code snippet uses a slice of an array as an output argument to subroutine. In this subroutine, a pointer is set to the array, and a loop performed over its bounds.

program check_bounds

  implicit none
  integer, parameter :: n = 10, m1 = 5, m2 = 6
  integer, dimension(:,:), allocatable :: arr
  integer :: i
  allocate (arr (n, n))
  arr = 0
  call return_array (n, m1, m2, arr(:,m1:m2))

contains

  subroutine return_array (n, m1, m2, arr)
    integer, intent(in) :: n, m1, m2
    integer, dimension(:,m1:), intent(out), target :: arr
    integer :: i, j
    integer, dimension(:,:), pointer :: arrp
    print *, 'size of arr: ', size(arr,dim=1), size(arr,dim=2)
    !!! This works fine
    !do i = 1, n
    !  do j = m1, m2
    !    arr(i,j) = i+j
    !  end do
    !end do
    arrp => arr
    print *, 'size of arrp: ', size(arrp,dim=1), size(arrp,dim=2)
    do i = 1, n
      do j = m1, m2
        arrp(i,j) = i+j
      end do
    end do
  end subroutine return_array


end program check_bounds

When compiled without any options, the whole code runs fine. However, when using "-check bounds", the program crashes with the error message

forrtl: severe (408): fort: (2): Subscript #2 of the array ARRP has value 5 which is greater than the upper bound of 2

It seems that the correct array bounds are not transferred to the bound checking instance.

As a side remark, the program compiled with gfortran works well with the corresponding option.

 

 

 

 

 

0 Kudos

Accepted Solutions
Highlighted
Valued Contributor III
37 Views

I'll suggest you submit a support request at the Intel Online Service Center and include "regression in compiler 18" in your title and/or description.

https://supporttickets.intel.com/?lang=en-US

Here's a simpler example you can use as well and see what -check:bounds option does to LBOUND of arrp following pointer assignment; try the case without -check:bounds to see the difference.

program p
   integer :: a(1)
   call sub( 3, a )
contains
   subroutine sub( n, arr )
      integer, intent(in)            :: n
      integer, intent(inout), target :: arr(n:)
      integer, pointer :: parr(:)
      parr => arr
      print *, "lbound(arr): ", lbound(arr)
      print *, "lbound(parr): ", lbound(parr)
   end subroutine
end program

 

View solution in original post

0 Kudos
3 Replies
Highlighted
37 Views

I forgot to mention the compiler version: 18.0.0

In fact, this seems to be a regression, as the example works well for ifort 17.0.4 and 16.0.2.

0 Kudos
Highlighted
Valued Contributor III
38 Views

I'll suggest you submit a support request at the Intel Online Service Center and include "regression in compiler 18" in your title and/or description.

https://supporttickets.intel.com/?lang=en-US

Here's a simpler example you can use as well and see what -check:bounds option does to LBOUND of arrp following pointer assignment; try the case without -check:bounds to see the difference.

program p
   integer :: a(1)
   call sub( 3, a )
contains
   subroutine sub( n, arr )
      integer, intent(in)            :: n
      integer, intent(inout), target :: arr(n:)
      integer, pointer :: parr(:)
      parr => arr
      print *, "lbound(arr): ", lbound(arr)
      print *, "lbound(parr): ", lbound(parr)
   end subroutine
end program

 

View solution in original post

0 Kudos
Highlighted
37 Views

Thank you for clarifying what actually goes wrong here. And also for pointing out where I can submit bug reports.

0 Kudos