Spurious array bounds warnings from gfortran

Allen McIntosh mcintosh@research.telcordia.com
Tue Oct 11 20:48:00 GMT 2011


Compiler version:  (gfortran from ubuntu 11.04)

$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 
4.5.2-8ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs 
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr 
--program-suffix=-4.5 --enable-shared --enable-multiarch 
--with-multiarch-defaults=x86_64-linux-gnu --enable-linker-build-id 
--with-system-zlib --libexecdir=/usr/lib/x86_64-linux-gnu 
--without-included-gettext --enable-threads=posix 
--with-gxx-include-dir=/usr/include/c++/4.5 
--libdir=/usr/lib/x86_64-linux-gnu --enable-nls --with-sysroot=/ 
--enable-clocale=gnu --enable-libstdcxx-debug 
--enable-libstdcxx-time=yes --enable-plugin --enable-gold 
--enable-ld=default --with-plugin-ld=ld.gold --enable-objc-gc 
--disable-werror --with-arch-32=i686 --with-tune=generic 
--enable-checking=release --build=x86_64-linux-gnu 
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)


Symptoms:  Compiling the file foo.F95 as shown below leads to the 
following warnings:

$ gfortran -c -O -Wall foo.F95
foo.F95: In function 'fooallocate':
foo.F95:8:0: warning: 'y.bar.dim[0].ubound' may be used uninitialized in 
this function
foo.F95:8:0: warning: 'y.bar2.dim[0].ubound' may be used uninitialized 
in this function

The code generated appears to be fine.

I believe that the warnings are spurious given the initialization 
pattern.  They're also rather brittle - for example, removing the 
definition and initialization of "junk" makes the warnings go away.

Contents of foo.F95:

$ cat foo.F95
MODULE x
   TYPE foo
     REAL, DIMENSION(:), POINTER :: bar => NULL()
     REAL, DIMENSION(:), POINTER :: bar2 => NULL()
     REAL :: junk = 75
   END TYPE foo
CONTAINS
   FUNCTION fooAllocate(n,r) RESULT(y)
     INTEGER, INTENT(IN) :: n
     INTEGER, INTENT(IN) :: r
     INTEGER len
     TYPE (foo) :: y
     len = 123
     IF(r == 1) THEN
       len = 42
     END IF
     SELECT CASE(r)
       CASE(1)
         ALLOCATE(y%bar(len))
       CASE(5)
         ALLOCATE(y%bar2(n))
     END SELECT
     RETURN
   END FUNCTION fooAllocate
END MODULE x



More information about the Gcc-bugs mailing list