I am observing a strange behavior using allocatable arrays in the presence of internal subroutines.
Consider the following program:
program main
implicit none
integer*4 :: n = 5
real*8, allocatable, dimension(:,:) :: array
allocate(array(6,n))
end program
I compiled it with ftn95 /full_debug main.f90 /checkmate /link and started it using the debugger sdbg main.exe
The program simply allocates an array(6,5), as shown by the debugger in the 'Vars' window. There, the exact output is: ARRAY = REAL*8 (6, 5)
Adding /64 yields the same result.
So far, so good.
Now I simply add an empty internal subroutine (for completeness I will provide the whole code again):
program main
implicit none
integer*4 :: n = 5
real*8, allocatable, dimension(:,:) :: array
allocate(array(6,n))
contains
subroutine subsub
end subroutine
end program
Using the same compiler options in 32 bit and examining with sdbg still yields the same output for the allocated array. However, if I compile the second code with /64, suddenly the array bounds are complete nonsense. In my particular case, the output was
ARRAY = REAL*8 (0:21844080, 20752:20757)
but I expect these values to vary (these bounds are definitely trash).
Interestingly, I was not able to produce an access violation in this small example and even the lbound/ubound and size intrinsic functions seem to work fine (despite the debugger output...). Admittedly, I did not try too hard either. By the way, checkmate does not complain at all (is it yet implemented in 64 bit??).
However I think that this might be some sort of compiler bug since one of our applications is crashing with spurious out-of-bounds errors/access violations when compiled with 64 bits and whenever internal subroutines are being used, while it did work fine in 32 bit. Actually these crashes along with this problem lead to the idea of examining the behavior of ALLOCATE in presence of internal subroutines.
Thanks for your help! Have a nice weekend! 😃