Silverfrost Forums

Welcome to our forums

False subscript error detected

7 Aug 2020 12:54 #26188

I had occasion to compile a program that used Lapack/BLAS routines, and needed to compile the needed BLAS routines with /check. FTN95 detects a subscript error in a situation where (I think) that it should not. In order to make the error easy to investigate, I have constructed a short reproducer.

The test program takes a 4 X 4 matrix C, and copies rows 2-4 and columns 2-4 into a 3 X 3 matrix D.

program xsubmat
implicit none
real C(4,4),D(3,3)
integer i,j,ldc,ldd,m,n
!test of copying C(2:4,2:4) into D, with subscript checking
do i=1,4
   do j=1,4
      C(i,j)=10*j+i
   end do
end do
ldc=4; ldd=3; m=3; n=3
call sub(C(2,2),ldc,D,ldd,m,n)
print 10,(D(i,:),i=1,m)
10 format(3F6.0)
end program

subroutine sub(C,ldc,D,ldd,m,n)
implicit none
integer i,ldc,ldd,m,n
real C(ldc,*),D(ldd,*)
do i=1,m
   D(1:n,i)=C(1:n,i)
end do
return
end subroutine

The Fortran 95 standard, section 12.4.1.1, says:

Except when a procedure reference is elemental (12.7), each element of an array-valued actual argument or of a sequence in a sequence association (12.4.1.4) is associated with the element of the dummy array that has the same position in array element order (6.2.2.2). My inference is that it should be OK to copy the sequence starting with C(2,2), which has 11 elements, 9 of which I wish to put into D.

In the debugger, after entering the subroutine, the variable list shows the effective dimensions of C in the subroutine as 4 X 2. It is debatable what it should show. However, there is no subscript error in the array copy. Please tell me if you do or do not agree.

7 Aug 2020 4:03 #26189

mecej4

Can you clarify please. Is this an error in FTN95 alone or does it also concern the debugger?

7 Aug 2020 4:47 #26190

Paul, I think that it is more an FTN95 issue. I ran the test program with NAG and Lahey compilers with their checking flags turned on, and there were no subscript errors reported. The Lapack code has been widely used for decades, and it would be unusual for the Lapack sources to retain subscript errors after such a long time.

Running the test program (compiled with /check) from the command line causes a subscript error to be reported, but it is not clear which variable/subscript was the cause. I had suggested some time ago that in such cases it would be helpful if the particular variable and subscript names were given in the error message, rather than just the line number.

I used the debugger only to see which subscript/array variable was being flagged as accessed outside its proper ranges.

8 Aug 2020 6:50 #26193

Thank you. I have made a note of this.

10 Aug 2020 9:22 #26208

This has now been fixed for the next release of FTN95.

Please login to reply.