This is the mail archive of the gcc-bugs@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]

[Bug fortran/32298] MINLOC / MAXLOC: off-by one for PARAMETER arrays



------- Comment #2 from dfranke at gcc dot gnu dot org  2007-06-16 14:00 -------
A simplified testcase:

$> cat pr32298.f90
PROGRAM ERR_MINLOC
  INTEGER, PARAMETER :: N = 7
  DOUBLE PRECISION, DIMENSION (N), PARAMETER :: A &
    = (/ 0.3D0, 0.455D0, 0.6D0, 0.7D0, 0.72D0, 0.76D0, 0.79D0 /)

  INTEGER :: I, K
  I = 7
  K = MAXLOC (ABS (A - A(I)), 1)

  PRINT *, I, K
END PROGRAM ERR_MINLOC

$> gfortran-svn -fdump-tree-original pr32298.f90
$> cat pr32298.f90.003t.original
[...]
    pos.0 = 0;
    {
      int4 S.3;
      S.3 = 0;
      while (1)
        {
          if (S.3 > 6) goto L.1;
          if (ABS_EXPR <A.2[S.3] - D.1011> > limit.1 || pos.0 == 0)
            {
              limit.1 = ABS_EXPR <A.2[S.3] - D.1011>;
              pos.0 = S.3;
            }
          S.3 = S.3 + 1;
        }
      L.1:;
    }
    k = pos.0 + 1;
  }

Variable pos.0 starts at 0 and thus triggers the right part of the or-clause
within the if-statement. Hence, it gets assigned the value of S.3, which
happens to be 0 within the first iteration. Within the second iteration of the
while, pos.0 still equals 0 which triggers the if-statement again - pos.0 will
now be set to 1 as S.3 was increased during the last iteration. At the end, K
ist set to pos.0 + 1, which (wrongly) equals 2 in this case.

Someone who intimiately knows the scalarizer should be able to fix this
easily?!


> (This might also affect MAXVAL/MINVAL, though I did not manage to cook 
> up an example.)

I don't think so as MINVAL/MAXVAL do not track the respective positions.


-- 

dfranke at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dfranke at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32298


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