Fix may be uninitialized warnings in libgfortran

Steven Bosscher stevenb@suse.de
Sun May 15 15:30:00 GMT 2005


On Sunday 15 May 2005 17:26, Paul Brook wrote:
> On Sunday 15 May 2005 16:19, Steven Bosscher wrote:
> > On Sunday 15 May 2005 14:40, Andreas Jaeger wrote:
> > > We get a number of these warnings in libgfortran:
> > >
> > > /cvs/gcc/libgfortran/generated/eoshift1_4.c:73: warning: ‘len’ may be
> > > used uninitialized in this function
> > >
> > > All of them look like false positives but the algorithm is written in
> > > a way that the compiler cannot catch it.  I propose to initialize the
> > > warnings - this is AFAIK the same way we do in the rest of the
> > > compiler.
> >
> > It's IMHO a bad thing to do.  Can't we just write that loop differently,
> > e.g. something like the following?
> >
> > Index: m4/eoshift1.m4
> > ===================================================================
> > RCS file: /cvs/gcc/gcc/libgfortran/m4/eoshift1.m4,v
> > retrieving revision 1.7
> > diff -u -3 -p -r1.7 eoshift1.m4
> > --- m4/eoshift1.m4      4 May 2005 21:38:15 -0000       1.7
> > +++ m4/eoshift1.m4      15 May 2005 15:19:02 -0000
> > @@ -91,7 +91,8 @@ eoshift1_`'atype_kind (const gfc_array_c
> >    count[0] = 0;
> >    size = GFC_DESCRIPTOR_SIZE (array);
> >    n = 0;
> > -  for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
> > +  dim = 0;
> > +  do
> >      {
> >        if (dim == which)
> >          {
>
> This wouldn't help. The warning is technically correct.
> The compiler has no way of proving 0 <= which < rank(array).

OK, then I guess there's no other way around this other than adding those
initializations.  Too bad...

Gr.
Steven



More information about the Fortran mailing list