0

When I compile this silly fortran routine:

SUBROUTINE MY (C,M,NA,A,NB,B,N,V,I1,I2)
IMPLICIT NONE
INTEGER :: M, NA, NB, N, I, J, I1, I2
REAL :: C, A(NA,M), B(NB,M), V(N), X
IF(M.GT.15) THEN
  DO I=1,N
    X=C*V(I)
    CALL DAXPY(M,X,A(I1,1),NA,B(I2,1),NB)
  END DO
ELSE
  DO I=1,N
    X=C*V(I)
    DO J=1,M
      B(I2,J)=B(I2,J)+A(I1,J)
    END DO
  END DO
END IF
END SUBROUTINE MY

with gfortran -fsanitize=address -O2 -Wall -c a.f90 (gcc version 4.8.4) I get this warning:

a.f90: In function ‘my’:
a.f90:4:0: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 REAL :: C, A(NA,M), B(NB,M), V(N), X
 ^

and I can't see how x could ever be uninitialized (only if N < 1, but then it's never used either). The warning goes away without -fsanitize=address or -O2. Is any of these options changing my code in some "unsafe" way (such that the warning is issued)? Do more recent gfortran version give the same message?

Jellby
  • 2,360
  • 3
  • 27
  • 56
  • You should look what kind of code gfortran generates with the optimizations by -fdump-tree-optimized . The optimizer and sanitizer might create some code path where that is possible, but cannot be reached in practice. It may be a sign of wrong code generated by the compiler. – Vladimir F Героям слава May 06 '16 at 13:39
  • 1
    Though not very sure if some issue may exist with X, at least gfortran-5.2 and 6.0 (on Linux) and 5.3 and 6.0 (on Mac) gave no warning with the same options. So maybe no problem for this particular example...? – roygvib May 06 '16 at 14:45
  • 1
    I am quite sure it is bogus with respect to the standard, but that compiler version may be generating a code path which is indeed possibly uninitialized. It may be a bug in the compiler in that version. – Vladimir F Героям слава May 06 '16 at 16:55
  • In the ELSE clause loop, x is set but never used. Remove that statement and see if the warning still exists. – FredK May 11 '16 at 17:10
  • @FredK Yes (I mean, no, the warning disappears), but if I write `X*A(I1,J)` I still get the same warning, and `X` is no longer unused. – Jellby May 13 '16 at 13:54

0 Answers0