Fix may be uninitialized warnings in libgfortran

Erik Schnetter schnetter@aei.mpg.de
Sun May 15 15:42: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).

You could assert the compiler that this is so:

	assert (0 <= which && which < rank(array));

Of course I'm saying this tongue-in-cheek because gcc is not actually 
smart enough to make use of the assertion in the following code.

-erik

-- 
Erik Schnetter <schnetter@aei.mpg.de>   http://www.aei.mpg.de/~eschnett/

My email is as private as my paper mail.  I therefore support encrypting
and signing email messages.  Get my PGP key from www.keyserver.net.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20050515/69235ef6/attachment.sig>


More information about the Fortran mailing list