Bug 47386 - Wrong warning: ‘w.dim[2].stride’ may be used uninitialized in this function [-Wuninitialized]
Summary: Wrong warning: ‘w.dim[2].stride’ may be used uninitialized in this function [...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2011-01-20 21:19 UTC by Harald Anlauf
Modified: 2022-09-04 08:59 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 10.2.0, 11.0, 12.2.0, 4.6.0, 4.8.4, 4.9.4, 5.5.0, 6.4.0, 7.2.0, 8.3.0, 9.1.0
Last reconfirmed: 2021-04-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Harald Anlauf 2011-01-20 21:19:45 UTC
Hi.

the following testcase demonstrates warnings that can be irritating:

% cat gfcbug112.f90
module gfcbug112
  implicit none
  logical             :: ll = .false.
contains
  subroutine calc_W (N, M)
    integer, intent(in) :: N, M

    real                :: T(N,M,M) ! Temporary array 1
    real, allocatable   :: W(:,:,:) ! Temporary array 2

    if(ll) then
       allocate (W(N,M,M))
    end if

    T=0

    if(ll) then
       W = 0
       deallocate (W)
    end if

  end subroutine calc_W
end module gfcbug112
% gfc-trunk -c -Wall -O gfcbug112.f90
gfcbug112.f90: In function ‘calc_w’:
gfcbug112.f90:5:0: warning: ‘w.dim[2].stride’ may be used uninitialized in this function [-Wuninitialized]


One can get really many of these in large modules...

Harald
Comment 1 Andrew Pinski 2011-01-20 21:21:58 UTC
This is the "standard" uninitialized warning for predicates.  There are a few other bugs like this.
Comment 2 Richard Biener 2011-01-21 11:12:28 UTC
Confirmed.
Comment 3 Martin Sebor 2021-04-15 00:46:06 UTC
Reconfirmed with GCC 11 and the output below.

$ gcc -O2 -S -Wall pr47386.f90
pr47386.f90:9:35:

    9 |     real, allocatable   :: W(:,:,:) ! Temporary array 2
      |                                   ^
Warning: ‘w.dim[1].stride’ may be used uninitialized in this function [-Wmaybe-uninitialized]
pr47386.f90:18:12:

   18 |        W = 0
      |            ^
Warning: ‘w.dim[0].ubound’ may be used uninitialized in this function [-Wmaybe-uninitialized]
pr47386.f90:9:35:

    9 |     real, allocatable   :: W(:,:,:) ! Temporary array 2
      |                                   ^
Warning: ‘w.dim[2].ubound’ may be used uninitialized in this function [-Wmaybe-uninitialized]
pr47386.f90:9:35: Warning: ‘w.offset’ may be used uninitialized in this function [-Wmaybe-uninitialized]
pr47386.f90:9:35: Warning: ‘w.dim[2].stride’ may be used uninitialized in this function [-Wmaybe-uninitialized]
pr47386.f90:9:35: Warning: ‘w.dim[1].ubound’ may be used uninitialized in this function [-Wmaybe-uninitialized]
Comment 4 Richard Biener 2022-08-29 13:44:43 UTC
Re-confirmed with GCC 12 and trunk.  We diagnose a use of w.dim[1].ubound
conditional on ubound.1 > 0 && ll == 0.  I believe we're jump-threading
if (ll) around the T = 0 stmt and then mixing up paths.  -fno-thread-jumps fixes
the thing.