https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81889
Bug ID: 81889 Summary: [7 Regression] bogus warnings with -Wmaybe-uninitialized -O3 Product: gcc Version: 7.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: janus at gcc dot gnu.org Target Milestone: --- Please consider this simple Fortran test case: module m type t integer, dimension(:), pointer :: list end type contains subroutine s(n, p, Y) integer, intent(in) :: n type(t) :: p real, dimension(:) :: Y real, dimension(1:16) :: xx if (n > 3) then xx(1:n) = 0. print *, xx(1:n) else xx(1:n) = Y(p%list(1:n)) print *, sum(xx(1:n)) end if end subroutine end module When compiled with "gfortran-7 -Wmaybe-uninitialized -O3 -c", it yields: maybe_uninit.f90:21:0: print *, sum(xx(1:n)) Warning: ‘xx[3]’ may be used uninitialized in this function [-Wmaybe-uninitialized] maybe_uninit.f90:21:0: Warning: ‘xx[4]’ may be used uninitialized in this function [-Wmaybe-uninitialized] maybe_uninit.f90:21:0: Warning: ‘xx[5]’ may be used uninitialized in this function [-Wmaybe-uninitialized] maybe_uninit.f90:21:0: Warning: ‘xx[6]’ may be used uninitialized in this function [-Wmaybe-uninitialized] maybe_uninit.f90:21:0: Warning: ‘xx[7]’ may be used uninitialized in this function [-Wmaybe-uninitialized] maybe_uninit.f90:21:0: Warning: ‘xx[8]’ may be used uninitialized in this function [-Wmaybe-uninitialized] maybe_uninit.f90:21:0: Warning: ‘xx[9]’ may be used uninitialized in this function [-Wmaybe-uninitialized] maybe_uninit.f90:21:0: Warning: ‘xx[10]’ may be used uninitialized in this function [-Wmaybe-uninitialized] maybe_uninit.f90:21:0: Warning: ‘xx[11]’ may be used uninitialized in this function [-Wmaybe-uninitialized] maybe_uninit.f90:21:0: Warning: ‘xx[12]’ may be used uninitialized in this function [-Wmaybe-uninitialized] maybe_uninit.f90:21:0: Warning: ‘xx[13]’ may be used uninitialized in this function [-Wmaybe-uninitialized] maybe_uninit.f90:21:0: Warning: ‘xx[14]’ may be used uninitialized in this function [-Wmaybe-uninitialized] maybe_uninit.f90:21:0: Warning: ‘xx[15]’ may be used uninitialized in this function [-Wmaybe-uninitialized] Obviously no value that is used is actually uninitialized. gfortran 6 and earlier does not show these warnings. Also decreasing the optimization level makes them disappear.