This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fix may be uninitialized warnings in libgfortran
- From: Steven Bosscher <stevenb at suse dot de>
- To: fortran at gcc dot gnu dot org
- Cc: Andreas Jaeger <aj at suse dot de>, gcc-patches at gcc dot gnu dot org
- Date: Sun, 15 May 2005 17:19:39 +0200
- Subject: Re: Fix may be uninitialized warnings in libgfortran
- References: <m3hdh4mzlw.fsf@gromit.moeb>
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)
{
@@ -114,6 +115,8 @@ eoshift1_`'atype_kind (const gfc_array_c
n++;
}
}
+ while (++dim < GFC_DESCRIPTOR_RANK (array));
+
if (sstride[0] == 0)
sstride[0] = size;
if (rstride[0] == 0)
Gr.
Steven