User account creation filtered due to spam.
With the example code below, gfortran (4.5.0 and 4.6.0) give a strange warning message with -O2 flag:
> gfortran -Wall -O2 -c readmo.f90
readmo.f90: In function 'readmo':
readmo.f90:4:0: warning: 'convrt' may be used uninitialized in this function
When with -O0, the warning message disappear.
In fact, the array 'lopt' is not initialized in the code, however, the compiler does not give warning about that. I try the same code with g95, it give a warning message 'used but not set' about 'lopt'.
Any suggestions or comments? Thanks in advance!
!!!! example code readmo.f90 !!!!
real :: convrt
integer :: i, iflag, j
integer, dimension(3,5) :: lopt
iflag = 0
do i = 1, 5
do j = 1, 3
if ( lopt(j,i) < 0 ) then
convrt = 1.0
if ( j > 1 ) convrt = 2.0
iflag = 1
if ( iflag /= 0 ) then
do i = 1, 5
end subroutine readmo
Move to middle end. From the dump:
iflag = 0;
if (lopt[((integer(kind=8)) j + (integer(kind=8)) i * 3) + -4] < 0)
convrt = 1.0e+0;
iflag = 1;
if (iflag != 0)
... access convrt ...
Thus, lopt is never set, but not warned for. But convrt is only accessed if it is set. However, the middle-end (with optimization) only has
warning: 'convrt' may be used uninitialized in this function
> In fact, the array 'lopt' is not initialized in the code, however, the compiler
> does not give warning about that. I try the same code with g95, it give a
> warning message 'used but not set' about 'lopt'.
Add lopt(1,1) = 0 at the beginning of your code and the g95 warning just disappears!
So don't rely too much of this kind of warning.
> Any suggestions or comments? Thanks in advance!
Searching bugzilla for "uninitialized" in the subject yields 52 entries for open pr (not counting those closed as INVALID, DUPLICATE, WONTFIX, ...). I let you browse the list to check if this pr is a duplicate of one of those (look for instance to pr24639, my choice is pr27120).
As far as I understand the problem,
(1) it could be as difficult to solve as running the code itself (think of an array of 10**9 elements set through a spaghetti code and forgetting to set only one element). Note this apply also to duplicate initialization (as in Fortran legalese;-).
(2) the responsibility to use only set variables is on the user, not on the compiler.