From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22363 invoked by alias); 16 Jun 2007 14:00:14 -0000 Received: (qmail 22208 invoked by uid 48); 16 Jun 2007 14:00:03 -0000 Date: Sat, 16 Jun 2007 14:00:00 -0000 Message-ID: <20070616140003.22206.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug fortran/32298] MINLOC / MAXLOC: off-by one for PARAMETER arrays In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "dfranke at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-06/txt/msg01278.txt.bz2 ------- 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 > limit.1 || pos.0 == 0) { limit.1 = ABS_EXPR ; 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