title: Gfortran warnings complaining "Wmaybe-uninitialized"
body: <p>I am recently developing a fairly long Fortran code. The compiler that I am using is gfortran 4.8.1 on Opensuse 13.1 (64-bit). However when I compiled the code with -O2 or -O3 options, I got many warnings about "-Wmaybe-uninitialized". I managed to reduce the code to a minimal working example as shown below. </p>
  
  <p>In main.f90</p>
  
  <pre><code>program main
      use modTest
      implicit none
  
      real(kind = 8), dimension(:, :), allocatable :: output
      real(kind = 8), dimension(:, :, :), allocatable :: input
  
      allocate(input(22, 33, 20), output(22, 33))
      input = 2.0
      call test(input, output)
  
  end program main
  </code></pre>
  
  <p>In test.f90</p>
  
  <pre><code>module modTest
  contains
  subroutine test(inputValue, outValue)
      use modGlobal
      implicit none
  
      real(kind = 8), dimension(:, :, :), intent(in) :: inputValue
      real(kind = 8), dimension(:, :), intent(out) :: outValue
      integer :: nR, nX, nM, iM, ALLOCATESTATUS
      real, dimension(:, :, :), allocatable :: cosMPhi
  
      nR = size(inputValue, 1)
      nX = size(inputValue, 2)
      nM = size(inputValue, 3) - 1
      allocate(cosMPhi(nR, nX, 0:nM), stat=ALLOCATESTATUS)
      call checkStatus(ALLOCATESTATUS)
      do iM = 0, nM
          cosMPhi(:, :, iM) = cos(iM * 1.0)
      end do
      outValue =  sum(inputValue * cosMPhi, 3)
  
  end subroutine
  end module
  </code></pre>
  
  <p>In global.f90</p>
  
  <pre><code>module modGlobal
  contains
      subroutine checkStatus(stat)
          implicit none
          integer, intent(in) :: stat
          if(stat /= 0) then
             print *, "allocation failed"
             stop
          end if
     end subroutine
  end module
  </code></pre>
  
  <p>When compiled using <code>gfortran -O2 -Wall test.f90 main.f90 -o run</code>, the following warnings appear:</p>
  
  <pre><code>test.f90: In function 'test':
  test.f90:9:0: warning: 'cosmphi.dim[2].stride' may be used uninitialized in this function [-Wmaybe-uninitialized]
       real, dimension(:, :, :), allocatable :: cosMPhi
  ^
  test.f90:9:0: warning: 'cosmphi.dim[1].ubound' may be used uninitialized in this function [-Wmaybe-uninitialized]
  test.f90:9:0: warning: 'cosmphi.dim[1].stride' may be used uninitialized in this function [-Wmaybe-uninitialized]
  test.f90:9:0: warning: 'cosmphi.dim[0].ubound' may be used uninitialized in this function [-Wmaybe-uninitialized]
  test.f90:9:0: warning: 'cosmphi.offset' may be used uninitialized in this function [-Wmaybe-uninitialized]
  </code></pre>
  
  <p>Though I tried to google this issue for some time, I still failed to find a good answer. Some relevant websites are:
  (1) <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58410" rel="nofollow noreferrer">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58410</a>
  (2) <a href="https://groups.google.com/forum/m/#!topic/comp.lang.fortran/RRYoulcSR1k" rel="nofollow noreferrer">https://groups.google.com/forum/m/#!topic/comp.lang.fortran/RRYoulcSR1k</a>
  (3)<a href="https://stackoverflow.com/questions/14132898/gcc-wuninitialized-wmaybe-uninitialized-issues">GCC -Wuninitialized / -Wmaybe-uninitialized issues</a></p>
  
  <p>I tested the example code using gfortran 4.8.5 and the warnings still persist. Was it because I did anything wrong in the code? Any help would be greatly appreciated. Thanks in advance!</p>