I came across a weird situation while trying to debug my code. I tried to reproduce it in a smaller program but unfortunately couldn't, so let me start by posting the relevant snippets:
subroutine sub(H) implicit none type(derived), intent(inout) :: H integer :: i, N ... N = size(H%field1) ! yields 24 ... do i = 1,N ... print*,i,N call module_sub(H%field2,H%field3) print*,i,N end do ... end subroutine sub
The full program, including the module containing sub (file ops.f90), compiles OK:
$ make ... ifort -O0 -c ops.f90 ... $ ifort -V Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 184.108.40.206 Build 20121010 Copyright (C) 1985-2012 Intel Corporation. All rights reserved. FOR NON-COMMERCIAL USE ONLY
There are no warnings when compiled with any / all of -warn all -debug full -check all -check bounds. Here is the relevant output of the two print statements shown above:
... 3 24 3 0 ...
Note that the variable N is defined in the beginning and never touched again and that it is not passed to module_sub. It is only used as an upper DO-loop bound after the second print. There is no connection to global variables whatsoever. The weird behavior disappears for -O1 and above and the code always prints the same initial value of N (=24 in the example above).
Is there any O0-related reason why ifort changes the value of this variable? If not, is this perhaps a known issue? If not and not, would it make sense to provide the full code (modified version that makes it easy to spot the relevant point, of course)?
Thanks in advance.