This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix may be uninitialized warnings in libgfortran


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).

Paul


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]