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]

[Patch, Fortran] PR31295 - Fix uninitialized variable


:ADDPATCH fortran:

For "eoshift((/1, 3/), 3)", eoshift0 is called with "which = 1". As the
array has only one dimension,
sstride[0] is never set in the "for (dim = 0; dim < GFC_DESCRIPTOR_RANK
(array); dim++)" loop.

Therefore,  "if (sstride[0] == 0)" uses the undefined value.

This patch silences the valgrind error, which should have no affect on
the result. (As Thomas wrote in the PR: "We are doing calculations with
the value, but don't actually use this for anything.")

With the patch, gfortran.dg/zero_sized_1.f90 and gfortran.dg/eoshift.f90
give no valgrind error ("Conditional jump or move depends on
uninitialised") any more.

Ok for the trunk? Build & regression tested on x86_64-unknown-linux-gnu
with no related failures.

Current failures:
- gfortran.fortran-torture/execute/st_function.f90, PR31095
- gfortran.dg/interface_12.f90 and gfortran.dg/result_in_spec_1.f90,
work with -O, fails with -O2 at runtime with:
Fortran runtime error: Attempt to allocate a negative amount of memory.

Tobias
2007-05-22  Tobias Burnus  <burnus@net-b.de>

	PR libgfortran/31295
	* intrinsics/eoshift0.c (eoshift0): Silence uninitialized warning.
	* intrinsics/eoshift2.c (eoshift2): Ditto.

Index: libgfortran/intrinsics/eoshift0.c
===================================================================
--- libgfortran/intrinsics/eoshift0.c	(Revision 124945)
+++ libgfortran/intrinsics/eoshift0.c	(Arbeitskopie)
@@ -88,10 +88,12 @@ eoshift0 (gfc_array_char * ret, const gf
 
   which = which - 1;
 
   extent[0] = 1;
   count[0] = 0;
+  sstride[0] = -1;
+  rstride[0] = -1;
   n = 0;
   for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
     {
       if (dim == which)
         {
Index: libgfortran/intrinsics/eoshift2.c
===================================================================
--- libgfortran/intrinsics/eoshift2.c	(Revision 124945)
+++ libgfortran/intrinsics/eoshift2.c	(Arbeitskopie)
@@ -92,10 +92,13 @@ eoshift2 (gfc_array_char *ret, const gfc
 
   which = which - 1;
 
   extent[0] = 1;
   count[0] = 0;
+  sstride[0] = -1;
+  rstride[0] = -1;
+  bstride[0] = -1;
   n = 0;
   for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
     {
       if (dim == which)
         {

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