Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29281 Discussions

catching error due to larger adjustable array at run-time

abhimodak
New Contributor I
690 Views

Hi

The test-case below captures the gist of an error; where is the cause that the adjustable array is bigger than what has been passed in. It cannot be caught by the compiler; I understand. I am wondering is there a way (as in a flag) to catch it at run-time. Compiling with ifort /check:all Test.f90 won't do.

As you can imagine this is extracted from rather deep inside a combination of legacy and new program. In one of the test-cases of that program, it revealed itself as "access violation" but that was at a different location. 

Abhi

---

      Module OM
         Implicit None
         Integer :: M, N
         Integer :: L
      Contains
      
         Subroutine Set()
            M = 3; N = 5
         End Subroutine Set
         
         Subroutine Tech(K)
            Integer :: K(N) ! Size is larger than what's passed; its incorrect.
            Integer :: L
            K = -1 ! any way to catch this error at run-time?
            L = K(N) - 1 ! or here?
            Write(*,"(2(A,X,I0,X))") "in Tech: K(N) =", K(N), " and L =", L
         End Subroutine Tech
         
      End Module OM
       
      Program Test
         Use OM
         Implicit None
         Integer, Allocatable :: I(:)
         
         Call Set()

         Allocate(I(M))
         I = 0
         Call Tech(I)
          Write(*,"(A,X,I0,X)") "after the call L =", L
         
      End Program Test      

 

0 Kudos
3 Replies
FortranFan
Honored Contributor III
690 Views

Did you try /check:bounds?

A question: can you not use assumed-shape array argument and if the length is inadequate, do some error handling instead?

subroutine Tech(K)
   
   ! Argument list
   integer :: K(:) !<-- assumed shape
   ..
   if ( size(K) < N ) then
    ! Size is shorter than desired, do the needful
     .. 

 

0 Kudos
abhimodak
New Contributor I
690 Views

Hi FortranFan

Thanks for your comment.

(a) As I mentioned, this doesn't get trapped with /check:all. So, no /check:bounds won't catch it.

(b) Yes, there are ways to rectify this. But since this is coming from some legacy things, I am wondering if it can't be caught. 

Abhi

0 Kudos
Steve_Lionel
Honored Contributor III
690 Views

Intel Fortran doesn't offer a check for this sort of thing. It would require passing extra information in a way that would break existing programs.

Better to use assumed-shape arrays.

0 Kudos
Reply