https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86330

            Bug ID: 86330
           Summary: False positive warnings about uninitialized
                    offset/lbound/ubound when allocating on assignment
           Product: gcc
           Version: 8.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tomastrnka at gmx dot com
  Target Milestone: ---

The following testcase generates false positive warnings because "x" is
unallocated before assignment:

program realloc_uninitialized
   implicit none

   integer, allocatable :: x(:)

!    allocate(x(0))
!    deallocate(x)
   x = foo()

   write(*,*) x

contains
   function foo() result(a)
      integer, allocatable :: a(:)

      allocate(a(5))
      a = 0
   end function
end program

$ gfortran -fdump-tree-original -Wall -O3 -fno-inline -o realloc_uninitialized
realloc_uninitialized.f90
realloc_uninitialized.f90:8:0:

    x = foo()

Warning: ‘x.offset’ is used uninitialized in this function [-Wuninitialized]
realloc_uninitialized.f90:8:0: Warning: ‘x.dim[0].lbound’ is used uninitialized
in this function [-Wuninitialized]
realloc_uninitialized.f90:8:0: Warning: ‘x.dim[0].ubound’ is used uninitialized
in this function [-Wuninitialized]

Uncommenting the allocate/deallocate makes the warning go away.
I'm using gcc version 8.1.1 20180502 (Red Hat 8.1.1-1) (GCC) (stock Fedora 28
compiler), but I have also seen this previously on GCC 7. My self-compiled gcc
version 6.4.1 20180314 (GCC) doesn't trigger the warning.

I guess this is because of the following references to "x" at the very start of
"realloc_uninitialized ()" in "realloc_uninitialized.f90.003t.original":
    D.3797 = (integer(kind=4)[0:] * restrict) x.data;
    D.3798 = x.offset;
    D.3799 = x.dim[0].lbound;
    D.3800 = x.dim[0].ubound;
None of these D.*s is subsequently used.

Reply via email to