public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dfranke at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/32298] MINLOC / MAXLOC: off-by one for PARAMETER arrays
Date: Sat, 16 Jun 2007 14:00:00 -0000	[thread overview]
Message-ID: <20070616140003.22206.qmail@sourceware.org> (raw)
In-Reply-To: <bug-32298-14685@http.gcc.gnu.org/bugzilla/>



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


  parent reply	other threads:[~2007-06-16 14:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-12  8:25 [Bug fortran/32298] New: Intrinsic MINLOC / MAXLOC gives wrong results (gfortran build 20070522) jens dot bischoff at freenet dot de
2007-06-12 16:05 ` [Bug fortran/32298] MINLOC / MAXLOC: off-by one for PARAMETER arrays burnus at gcc dot gnu dot org
2007-06-12 16:12 ` burnus at gcc dot gnu dot org
2007-06-16 14:00 ` dfranke at gcc dot gnu dot org [this message]
2007-06-20 12:15 ` pault at gcc dot gnu dot org
2007-06-21  5:05 ` patchapp at dberlin dot org
2007-06-24 11:04 ` pault at gcc dot gnu dot org
2007-06-24 11:06 ` pault at gcc dot gnu dot org
2007-10-15 18:24 ` tkoenig at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070616140003.22206.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).