'MEM[(struct m *)&s + 56B]' may be used uninitialized in this function

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

'MEM[(struct m *)&s + 56B]' may be used uninitialized in this function

Andrew Benson-3
With gfortran 8.0.1 the following code (reduced from a much larger code, so
there are obvious things wrong with it):

module mtc
  type :: t
     integer, allocatable, dimension(:) :: a
  end type t
  type :: m
     type(t), allocatable, dimension(:) :: fs
  end type m
contains
  subroutine ap(s,ps)
    class(m), intent(inout) :: s
    type(t), dimension(:), allocatable, intent(inout) :: ps
    ps(:)=[t([0]),t([0])]
  end subroutine ap
  function rcp() result(s)
    type(m) :: s
    type(t), allocatable, dimension(:) :: fs
    type(t), dimension(:), allocatable :: aps
    allocate(fs(2))
    s=m(fs)
    call ap(s,aps)
  end function rcp
end module mtc

gives the following when compiled:

$ gfortran -c 059.F90 -O1 -Wall
059.F90:9:17:

   subroutine ap(s,ps)
                 1
Warning: Unused dummy argument 's' at (1) [-Wunused-dummy-argument]
059.F90:19:0:

     s=m(fs)
 
Warning: 'MEM[(struct m *)&s + 48B]' may be used uninitialized in this
function [-Wmaybe-uninitialized]
059.F90:19:0: Warning: 'MEM[(struct m *)&s + 56B]' may be used uninitialized
in this function [-Wmaybe-uninitialized]
059.F90:19:0: Warning: 'fs.span' may be used uninitialized in this function [-
Wmaybe-uninitialized]

I can probably figure out what's causing the "may be used uninitialized" in
this reduced case, but I wondered if the:

'MEM[(struct m *)&s + 48B]'

is as intended, or if this should be the name of some member variable in type
"m" instead?

(The first warning, about the unused dummy argument, is easily fixed of course,
but if I remove the dummy argument the maybe-uninitialized warning goes away.)

-Andrew

Reply | Threaded
Open this post in threaded view
|

Re: 'MEM[(struct m *)&s + 56B]' may be used uninitialized in this function

Dominique d'Humières-2
Hi Andrew,

I think this a duplicate of pr86117 and probably others. The warnings come from the middle-end, but I don’t know if the problem comes from gfortran or not.

Cheers,

Dominique

Reply | Threaded
Open this post in threaded view
|

Re: 'MEM[(struct m *)&s + 56B]' may be used uninitialized in this function

Andrew Benson-3
Hi Dominique,

Thanks - that does look like the same problem. I'll add myself to the CC list
for that PR.

Cheers,
Andrew

On Thursday, June 14, 2018 3:40:52 PM PDT Dominique d'Humières wrote:
> Hi Andrew,
>
> I think this a duplicate of pr86117 and probably others. The warnings come
> from the middle-end, but I don’t know if the problem comes from gfortran or
> not.
>
> Cheers,
>
> Dominique


--

* Andrew Benson: http://users.obs.carnegiescience.edu/abenson/contact.html

* Galacticus: https://bitbucket.org/abensonca/galacticus