This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [Patch, libgfortran] PR 41219 Silence uninitialized variable warning
On Mon, Sep 07, 2009 at 12:16:35PM +0200, Richard Guenther wrote:
> On Mon, Sep 7, 2009 at 12:13 PM, Martin Jambor<mjambor@suse.cz> wrote:
> > On Sun, Sep 06, 2009 at 02:59:18PM +0200, Richard Guenther wrote:
> >> On Sun, Sep 6, 2009 at 2:56 PM, Janne
> >> Blomqvist<blomqvist.janne@gmail.com> wrote:
> >> > Hi,
> >> >
> >> > the patch below fixes the "use of uninitialized variable" warning in
> >> > unix.c. It's a spurious warning as the fstat() call will initialize
> >> > the stat struct, but gcc can't see it.
> >>
> >> Huh, that looks odd. ÂI bet this is SRA at work.
> >>
> >
> > I haven't examined this more than looking at the hunk below... but
> > isn't statbuf sort of too much TREE_ADDRESSABLE for SRA? ÂI reckon
> > that fstat cannot be optimized away...
>
> I was thinking that SRA might insert a (useless) copy like
>
> SR1 = stat.A;
> SR2 = stat.B;
> stat.A = SR1;
> stat.B = SR2;
> fstat(&stat);
>
> which then looks like uninitialized loads. But I didn't investigate either.
>
Still, since statbuf is addressable, SRA would only touch it if other
aggregate, which is being scalarized, would load/store (the whole
or a part of itself) from/to it. And that is not the case.
Moreover, I have now actually looked at the dumps and both SRA and
early SRA do nothing in that function.
Martin
> Richard.
>
> > Martin
> >
> >> Richard.
> >>
> >> > Ok for trunk?
> >> >
> >> > 2009-09-06 Janne Blomqvist <jb@gcc.gnu.org>
> >> >
> >> > PR libfortran/39667
> >> > * io/unix.c (fd_to_stream): Silence uninitialized warning.
> >> >
> >> >
> >> > diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
> >> > index 4ecba3a..e26f281 100644
> >> > --- a/libgfortran/io/unix.c
> >> > +++ b/libgfortran/io/unix.c
> >> > @@ -759,6 +759,10 @@ fd_to_stream (int fd, int prot)
> >> > s->logical_offset = 0;
> >> > s->prot = prot;
> >> >
> >> > + /* Silence compiler warnings about using unitialized variables. */
> >> > + statbuf.st_mode = 0;
> >> > + statbuf.st_size = 0;
> >> > +
> >> > /* Get the current length of the file. */
> >> >
> >> > fstat (fd, &statbuf);
> >> >
> >> >
> >> > --
> >> > Janne Blomqvist
> >> >
> >